|
@@ -41,6 +41,187 @@ slop::GLSelectRectangle::~GLSelectRectangle() {
|
41
|
41
|
usleep( 10000 );
|
42
|
42
|
}
|
43
|
43
|
|
|
44
|
+void slop::GLSelectRectangle::constrainWithinMonitor( int* x, int* y, int* w, int* h ) {
|
|
45
|
+ m_offsetx = 0;
|
|
46
|
+ m_offsety = 0;
|
|
47
|
+ m_offsetw = 0;
|
|
48
|
+ m_offseth = 0;
|
|
49
|
+ for ( unsigned int i=0;i<m_monitors.size();i++ ) {
|
|
50
|
+ XRRCrtcInfo* monitor = m_monitors[ i ];
|
|
51
|
+ if ( !((int)xengine->m_mousex >= (int)monitor->x && (int)xengine->m_mousey >= (int)monitor->y &&
|
|
52
|
+ (int)xengine->m_mousex <= (int)(monitor->x+monitor->width) && (int)xengine->m_mousey <= (int)(monitor->y+monitor->height) ) ) {
|
|
53
|
+ continue;
|
|
54
|
+ }
|
|
55
|
+ if ( (int)*x < (int)monitor->x ) {
|
|
56
|
+ m_offsetx = monitor->x-*x;
|
|
57
|
+ *w += *x-monitor->x;
|
|
58
|
+ *x = monitor->x;
|
|
59
|
+ }
|
|
60
|
+ if ( (int)(*x+*w) >= (int)(monitor->x+monitor->width) ) {
|
|
61
|
+ m_offsetw = (monitor->width-1-(*x-monitor->x+*w));
|
|
62
|
+ *w = monitor->width-1-(*x-monitor->x);
|
|
63
|
+ }
|
|
64
|
+ if ( (int)*y < (int)monitor->y ) {
|
|
65
|
+ m_offsety = monitor->y-*y;
|
|
66
|
+ *h += *y-monitor->y;
|
|
67
|
+ *y = monitor->y;
|
|
68
|
+ }
|
|
69
|
+ if ( (int)(*y+*h) >= (int)(monitor->y+monitor->height) ) {
|
|
70
|
+ m_offseth = (monitor->height-1-(*y-monitor->y+*h));
|
|
71
|
+ *h = monitor->height-1-(*y-monitor->y);
|
|
72
|
+ }
|
|
73
|
+ break;
|
|
74
|
+ }
|
|
75
|
+ m_offsetx *= m_glassSize;
|
|
76
|
+ m_offsety *= m_glassSize;
|
|
77
|
+ m_offsetw *= m_glassSize;
|
|
78
|
+ m_offseth *= m_glassSize;
|
|
79
|
+}
|
|
80
|
+
|
|
81
|
+void slop::GLSelectRectangle::setMagnifySettings( bool on, float magstrength, unsigned int pixels ) {
|
|
82
|
+ m_glassSize = magstrength;
|
|
83
|
+ m_glassPixels = pixels;
|
|
84
|
+ m_glassEnabled = on;
|
|
85
|
+ m_glassx = xengine->m_mousex;
|
|
86
|
+ m_glassy = xengine->m_mousey;
|
|
87
|
+ m_realglassx = xengine->m_mousex;
|
|
88
|
+ m_realglassy = xengine->m_mousey;
|
|
89
|
+}
|
|
90
|
+
|
|
91
|
+void slop::GLSelectRectangle::pushOut( int* x, int* y, int w, int h, int rx, int ry, int rw, int rh ) {
|
|
92
|
+ // AABB to test for collision
|
|
93
|
+ if (!(
|
|
94
|
+ *x < rx + rw &&
|
|
95
|
+ *x + w > rx &&
|
|
96
|
+ *y < ry + rh &&
|
|
97
|
+ h + *y > ry
|
|
98
|
+ )) {
|
|
99
|
+ // No collision, so we do nothing.
|
|
100
|
+ return;
|
|
101
|
+ }
|
|
102
|
+ // Otherwise we find an optimal angle to push ourselves out at.
|
|
103
|
+ int centerx = rx+rw/2;
|
|
104
|
+ int centery = ry+rh/2;
|
|
105
|
+ float ang = -atan2( (float)(*y+(float)h/2.f)-(float)centery, (float)(*x+(float)w/2.f)-(float)centerx );
|
|
106
|
+ float pi = 3.1415926535897;
|
|
107
|
+ float upright = pi/2 - atan( (2.f*float(rx+rw)-2.f*(float)centerx)/(float)rh );
|
|
108
|
+ float upleft = pi/2 - atan( (2.f*(float)rx-2.f*(float)centerx)/(float)rh );
|
|
109
|
+ float downright = -upright;
|
|
110
|
+ float downleft = -upleft;
|
|
111
|
+ if ( ang >= upright && ang <= upleft ) {
|
|
112
|
+ *x = centerx + ((rh*cos(ang))/(2*sin(ang))) - w/2;
|
|
113
|
+ *y = centery - rh/2 - h;
|
|
114
|
+ } else if ( ang <= downright && ang >= downleft) {
|
|
115
|
+ *x = centerx - ((rh*cos(ang))/(2*sin(ang))) - w/2;
|
|
116
|
+ *y = centery + rh/2;
|
|
117
|
+ } else if ( ang < downleft || ang > upleft ) {
|
|
118
|
+ *x = centerx - rw/2 - w;
|
|
119
|
+ *y = centery + (rw*sin(ang))/(2*cos(ang)) - h/2;
|
|
120
|
+ } else {
|
|
121
|
+ *x = centerx + rw/2;
|
|
122
|
+ *y = centery - (rw*sin(ang))/(2*cos(ang)) - h/2;
|
|
123
|
+ }
|
|
124
|
+}
|
|
125
|
+
|
|
126
|
+void slop::GLSelectRectangle::pushIn( int* x, int* y, int w, int h, int rx, int ry, int rw, int rh ) {
|
|
127
|
+ if ( *x > rx && *y > ry &&
|
|
128
|
+ *x+w < rx+rw && *y+h < ry+rh ) {
|
|
129
|
+ // We're already fully contained...
|
|
130
|
+ return;
|
|
131
|
+ }
|
|
132
|
+ // Otherwise we find an optimal angle to push ourselves in at.
|
|
133
|
+ int centerx = rx+rw/2;
|
|
134
|
+ int centery = ry+rh/2;
|
|
135
|
+ float ang = -atan2( (float)(*y+(float)h/2.f)-(float)centery, (float)(*x+(float)w/2.f)-(float)centerx );
|
|
136
|
+ float pi = 3.1415926535897;
|
|
137
|
+ float upright = pi/2 - atan( (2.f*float(rx+rw)-2.f*(float)centerx)/(float)rh );
|
|
138
|
+ float upleft = pi/2 - atan( (2.f*(float)rx-2.f*(float)centerx)/(float)rh );
|
|
139
|
+ float downright = -upright;
|
|
140
|
+ float downleft = -upleft;
|
|
141
|
+ if ( ang >= upright && ang <= upleft ) {
|
|
142
|
+ *x = centerx + ((rh*cos(ang))/(2*sin(ang))) - w/2;
|
|
143
|
+ *y = centery - rh/2;
|
|
144
|
+ } else if ( ang <= downright && ang >= downleft) {
|
|
145
|
+ *x = centerx - ((rh*cos(ang))/(2*sin(ang))) - w/2;
|
|
146
|
+ *y = centery + rh/2 - h;
|
|
147
|
+ } else if ( ang < downleft || ang > upleft ) {
|
|
148
|
+ *x = centerx - rw/2;
|
|
149
|
+ *y = centery + (rw*sin(ang))/(2*cos(ang)) - h/2;
|
|
150
|
+ } else {
|
|
151
|
+ *x = centerx + rw/2 - w;
|
|
152
|
+ *y = centery - (rw*sin(ang))/(2*cos(ang)) - h/2;
|
|
153
|
+ }
|
|
154
|
+ if ( !(*x > rx && *y > ry &&
|
|
155
|
+ *x+w < rx+rw && *y+h < ry+rh) ) {
|
|
156
|
+ if ( *x+w > rx+rw ) {
|
|
157
|
+ *x -= w/2;
|
|
158
|
+ }
|
|
159
|
+ if ( *x < rx ) {
|
|
160
|
+ *x += w/2;
|
|
161
|
+ }
|
|
162
|
+ if ( *y+h > ry+rh ) {
|
|
163
|
+ *y -= h/2;
|
|
164
|
+ }
|
|
165
|
+ if ( *y < ry ) {
|
|
166
|
+ *y += h/2;
|
|
167
|
+ }
|
|
168
|
+ }
|
|
169
|
+}
|
|
170
|
+
|
|
171
|
+void slop::GLSelectRectangle::findOptimalGlassPosition() {
|
|
172
|
+ // Try to move the glass next to the mouse.
|
|
173
|
+ m_glassx = xengine->m_mousex+m_glassPixels/2+5-m_glassBorder;
|
|
174
|
+ m_glassy = xengine->m_mousey+m_glassPixels/2+5-m_glassBorder;
|
|
175
|
+ XRectangle view, selection, combined;
|
|
176
|
+ view.x = xengine->m_mousex-(m_glassPixels+1+m_glassBorder)/2;
|
|
177
|
+ view.y = xengine->m_mousey-(m_glassPixels+1+m_glassBorder)/2;
|
|
178
|
+ view.width = m_glassPixels+1;
|
|
179
|
+ view.height = m_glassPixels+1;
|
|
180
|
+ selection.x = m_x-m_border;
|
|
181
|
+ selection.y = m_y-m_border;
|
|
182
|
+ selection.width = m_width+m_border*2;
|
|
183
|
+ selection.height = m_height+m_border*2;
|
|
184
|
+ combined.x = std::min( selection.x, view.x );
|
|
185
|
+ combined.y = std::min( selection.y, view.y );
|
|
186
|
+ combined.width = selection.width + std::max( selection.x-view.x, (view.x+view.width)-(selection.x+selection.width) );
|
|
187
|
+ combined.height = selection.height + std::max( selection.y-view.y, (view.y+view.height)-(selection.y+selection.height) );
|
|
188
|
+ for ( unsigned int i=0;i<m_monitors.size();i++ ) {
|
|
189
|
+ XRRCrtcInfo* monitor = m_monitors[ i ];
|
|
190
|
+ // Push the glass inside the monitor the mouse is on.
|
|
191
|
+ if ( (int)xengine->m_mousex >= (int)monitor->x && (int)xengine->m_mousex <= (int)(monitor->x + monitor->width) &&
|
|
192
|
+ (int)xengine->m_mousey >= (int)monitor->y && (int)xengine->m_mousey <= (int)(monitor->y + monitor->height) ) {
|
|
193
|
+ pushIn( &m_glassx, &m_glassy, m_glassPixels*m_glassSize+m_glassBorder*2, m_glassPixels*m_glassSize+m_glassBorder*2, monitor->x, monitor->y, monitor->width, monitor->height );
|
|
194
|
+ break;
|
|
195
|
+ }
|
|
196
|
+ }
|
|
197
|
+ // Push the glass outside of the selection, but only if we are left clicking, and always keep it out of the "shot"
|
|
198
|
+ if ( xengine->getCursor() != slop::Left ) {
|
|
199
|
+ pushOut( &m_glassx, &m_glassy, m_glassPixels*m_glassSize+m_glassBorder*2, m_glassPixels*m_glassSize+m_glassBorder*2, combined.x, combined.y, combined.width, combined.height );
|
|
200
|
+ } else {
|
|
201
|
+ pushOut( &m_glassx, &m_glassy, m_glassPixels*m_glassSize+m_glassBorder*2, m_glassPixels*m_glassSize+m_glassBorder*2, view.x, view.y, view.width, view.height );
|
|
202
|
+ }
|
|
203
|
+ m_glassx += m_glassBorder;
|
|
204
|
+ m_glassy += m_glassBorder;
|
|
205
|
+}
|
|
206
|
+
|
|
207
|
+void slop::GLSelectRectangle::generateMagnifyingGlass() {
|
|
208
|
+ int x = xengine->m_mousex-m_glassPixels/2;
|
|
209
|
+ int y = xengine->m_mousey-m_glassPixels/2;
|
|
210
|
+ int w = m_glassPixels;
|
|
211
|
+ int h = m_glassPixels;
|
|
212
|
+ constrainWithinMonitor( &x, &y, &w, &h );
|
|
213
|
+ XImage* image = XGetImage( xengine->m_display, xengine->m_root, x, y, w, h, 0xffffffff, ZPixmap );
|
|
214
|
+ glEnable(GL_TEXTURE_2D);
|
|
215
|
+ glGenTextures(1, &m_texid);
|
|
216
|
+ glBindTexture(GL_TEXTURE_2D, m_texid);
|
|
217
|
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
218
|
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
219
|
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
220
|
+ glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, (void*)(&(image->data[0])));
|
|
221
|
+ XDestroyImage( image );
|
|
222
|
+ glDisable(GL_TEXTURE_2D);
|
|
223
|
+}
|
|
224
|
+
|
44
|
225
|
slop::GLSelectRectangle::GLSelectRectangle( int sx, int sy, int ex, int ey, int border, bool highlight, float r, float g, float b, float a ) {
|
45
|
226
|
m_x = std::min( sx, ex );
|
46
|
227
|
m_y = std::min( sy, ey );
|
|
@@ -53,6 +234,14 @@ slop::GLSelectRectangle::GLSelectRectangle( int sx, int sy, int ex, int ey, int
|
53
|
234
|
m_border = border;
|
54
|
235
|
m_window = None;
|
55
|
236
|
m_highlight = highlight;
|
|
237
|
+ m_glassPixels = 64;
|
|
238
|
+ m_glassx = xengine->m_mousex;
|
|
239
|
+ m_glassy = xengine->m_mousey;
|
|
240
|
+ m_realglassx = xengine->m_mousex;
|
|
241
|
+ m_realglassy = xengine->m_mousey;
|
|
242
|
+ m_glassSize = 4;
|
|
243
|
+ m_glassBorder = 1;
|
|
244
|
+ m_monitors = xengine->getCRTCS();
|
56
|
245
|
|
57
|
246
|
// If we don't have a border, we don't exist, so just die.
|
58
|
247
|
if ( m_border == 0 ) {
|
|
@@ -178,7 +367,9 @@ void slop::GLSelectRectangle::setGeo( int sx, int sy, int ex, int ey ) {
|
178
|
367
|
m_y = y;
|
179
|
368
|
m_width = w;
|
180
|
369
|
m_height = h;
|
181
|
|
- glDrawBuffer( GL_BACK );
|
|
370
|
+}
|
|
371
|
+
|
|
372
|
+void slop::GLSelectRectangle::update( double dt ) {
|
182
|
373
|
glViewport( 0, 0, xengine->getWidth(), xengine->getHeight() );
|
183
|
374
|
|
184
|
375
|
glClearColor( 0, 0, 0, 0 );
|
|
@@ -191,14 +382,56 @@ void slop::GLSelectRectangle::setGeo( int sx, int sy, int ex, int ey ) {
|
191
|
382
|
glMatrixMode( GL_MODELVIEW );
|
192
|
383
|
glLoadIdentity();
|
193
|
384
|
|
194
|
|
- glEnable( GL_BLEND );
|
195
|
|
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
196
|
|
-
|
197
|
385
|
glColor4f( m_r, m_g, m_b, m_a );
|
198
|
386
|
glRecti( m_x-m_border, m_y, m_x+m_width+m_border, m_y-m_border );
|
199
|
387
|
glRecti( m_x-m_border, m_y+m_height, m_x+m_width+m_border, m_y+m_height+m_border );
|
200
|
388
|
glRecti( m_x-m_border, m_y, m_x, m_y+m_height );
|
201
|
389
|
glRecti( m_x+m_width, m_y, m_x+m_width+m_border, m_y+m_height );
|
202
|
390
|
|
|
391
|
+ if ( m_glassEnabled ) {
|
|
392
|
+ generateMagnifyingGlass();
|
|
393
|
+ findOptimalGlassPosition();
|
|
394
|
+
|
|
395
|
+ // Takes .1 second to reach the real position. Used for easing.
|
|
396
|
+ m_realglassx -= float(m_realglassx - (float)m_glassx) * dt * 10;
|
|
397
|
+ m_realglassy -= float(m_realglassy - (float)m_glassy) * dt * 10;
|
|
398
|
+
|
|
399
|
+ // Black outline...
|
|
400
|
+
|
|
401
|
+ glColor4f( 0, 0, 0, 1 );
|
|
402
|
+ glBegin( GL_QUADS );
|
|
403
|
+ glTexCoord2f(0.0, 1.0); glVertex3f( m_realglassx+m_offsetx-m_glassBorder, m_realglassy+(m_glassSize*m_glassPixels)+m_offseth+m_glassBorder, 0.0);
|
|
404
|
+ glTexCoord2f(1.0, 1.0); glVertex3f( m_realglassx+(m_glassSize*m_glassPixels)+m_offsetw+m_glassBorder, m_realglassy+(m_glassSize*m_glassPixels)+m_offseth+1, 0.0);
|
|
405
|
+ glTexCoord2f(1.0, 0.0); glVertex3f( m_realglassx+(m_glassSize*m_glassPixels)+m_offsetw+m_glassBorder, m_realglassy+m_offsety-m_glassBorder, 0.0);
|
|
406
|
+ glTexCoord2f(0.0, 0.0); glVertex3f( m_realglassx+m_offsetx-m_glassBorder, m_realglassy+m_offsety-m_glassBorder, 0.0);
|
|
407
|
+ glEnd();
|
|
408
|
+
|
|
409
|
+ glEnable( GL_TEXTURE_2D );
|
|
410
|
+ glBindTexture( GL_TEXTURE_2D, m_texid );
|
|
411
|
+ glColor4f( 1, 1, 1, 1 );
|
|
412
|
+ glBegin( GL_QUADS );
|
|
413
|
+ glTexCoord2f(0.0, 1.0); glVertex3f( m_realglassx+m_offsetx, m_realglassy+(m_glassSize*m_glassPixels)+m_offseth, 0.0);
|
|
414
|
+ glTexCoord2f(1.0, 1.0); glVertex3f( m_realglassx+(m_glassSize*m_glassPixels)+m_offsetw, m_realglassy+(m_glassSize*m_glassPixels)+m_offseth, 0.0);
|
|
415
|
+ glTexCoord2f(1.0, 0.0); glVertex3f( m_realglassx+(m_glassSize*m_glassPixels)+m_offsetw, m_realglassy+m_offsety, 0.0);
|
|
416
|
+ glTexCoord2f(0.0, 0.0); glVertex3f( m_realglassx+m_offsetx, m_realglassy+m_offsety, 0.0);
|
|
417
|
+ glEnd();
|
|
418
|
+ glDisable( GL_TEXTURE_2D );
|
|
419
|
+
|
|
420
|
+ glLogicOp(GL_INVERT);
|
|
421
|
+ glEnable(GL_COLOR_LOGIC_OP);
|
|
422
|
+ glLineWidth( 2 );
|
|
423
|
+ glColor4f( 0, 0, 0, 1 );
|
|
424
|
+ glBegin( GL_LINES );
|
|
425
|
+ float cx = m_realglassx+(m_glassSize*m_glassPixels)/2;
|
|
426
|
+ float cy = m_realglassy+(m_glassSize*m_glassPixels)/2;
|
|
427
|
+ glVertex3f( cx-5, cy, 0 );
|
|
428
|
+ glVertex3f( cx+5, cy, 0 );
|
|
429
|
+ glVertex3f( cx, cy-5, 0 );
|
|
430
|
+ glVertex3f( cx, cy+5, 0 );
|
|
431
|
+ glEnd();
|
|
432
|
+ glLogicOp(GL_NOOP);
|
|
433
|
+ glDisable(GL_COLOR_LOGIC_OP);
|
|
434
|
+ }
|
|
435
|
+
|
203
|
436
|
glXSwapBuffers( xengine->m_display, m_glxWindow );
|
204
|
437
|
}
|