#include "ImageSelectorWin.h" #include "jed.h" #include #include #include ImageSelectorWin::ImageSelectorWin() { xselection=50; yselection=50; xselectionsize=5; yselectionsize=5; } ImageSelectorWin::~ImageSelectorWin() { } void ImageSelectorWin::mouse(int button, int state, int x, int y) { if (button==GLUT_MIDDLE_BUTTON && state == GLUT_DOWN) { //puts ("middle down"); xselection=x; yselection=y; xselectionsize=yselectionsize=0; glutPostRedisplay(); } motion(x,y); } void ImageSelectorWin::motion(int x, int y) { if (leftbuttonstate==GLUT_DOWN) { if (xwidth-1) x=width-1-xselectionsize; if (yheight-1) y=height-1-yselectionsize; xselection=x; yselection=y; glutPostRedisplay(); } else if (middlebuttonstate==GLUT_DOWN) { //puts ("midddle motion"); xselectionsize = yselectionsize = MAX(0,MAX(x-xselection,y-yselection)); if (xselectionsize>((MIN(width,height))/2)-1) xselectionsize=yselectionsize=((MIN(width,height))/2)-1; //if (xselectionsize>20) // xselectionsize=yselectionsize=20; if (xselectionwidth-1) xselection=width-1-xselectionsize; if (yselectionheight-1) yselection=height-1-yselectionsize; glutPostRedisplay(); } } void ImageSelectorWin::display() { // Use ImageWin to draw picture ImageWin::display(); // Turn on stippling glEnable(GL_LINE_STIPPLE); // modified y int mody = height-1-yselection; // draw for (int stip=0; stip<2; stip++) { // Set first white then black stipple if (stip==0) { glColor3f(1,1,1); glLineStipple(3,0x5555); } else { glColor3f(0,0,0); glLineStipple(3,0xAAAA); } // Draw crosshairs glBegin(GL_LINES); glVertex2s(xselection,0); glVertex2s(xselection,height); glVertex2s(0,mody); glVertex2s(width, mody); glEnd(); // Draw box glBegin(GL_LINES); glVertex2s(xselection-xselectionsize,mody-yselectionsize); glVertex2s(xselection+xselectionsize,mody-yselectionsize); glVertex2s(xselection+xselectionsize,mody-yselectionsize); glVertex2s(xselection+xselectionsize,mody+yselectionsize); glVertex2s(xselection+xselectionsize,mody+yselectionsize); glVertex2s(xselection-xselectionsize,mody+yselectionsize); glVertex2s(xselection-xselectionsize,mody+yselectionsize); glVertex2s(xselection-xselectionsize,mody-yselectionsize); glEnd(); } glutSwapBuffers(); }