Almost ready image view OpenGL module

This commit is contained in:
Eddy
2015-03-01 14:37:23 +03:00
parent bf7a247678
commit 4e5d015e53
14 changed files with 806 additions and 335 deletions

View File

@@ -19,7 +19,7 @@
* MA 02110-1301, USA.
*/
#include "events.h"
#include "bmpview.h"
#include "imageview.h"
#include "macros.h"
/*
* æÕÎËÃÉÉ ÄÌÑ ÒÁÂÏÔÙ Ó OpenGL'ÎÙÍÉ ÓÏÂÙÔÉÑÍÉ
@@ -35,21 +35,29 @@ void keyPressed(unsigned char key, //
//DBG("Key pressed. mod=%d, keycode=%d, point=(%d,%d)\n", mod, key, x,y);
if((mod == GLUT_ACTIVE_CTRL) && (key == 'q' || key == 17)) exit(0); // ctrl + q
switch(key){
case '1': // return zoom to 1 & image to 0
win->zoom = 1;
win->x = 0; win->y = 0;
break;
// case 'i': more_info = !more_info;
// break;
case 27: destroyWindow(window, OPENGL);
break;
case 'p':
printf("z = %f\n", win->z);
printf("zoom = %f\n", win->zoom);
break;
// case 'm': createWindow(&mainWindow);
// break;
// case 'w': createWindow(&WaveWindow);
// break;
case 'Z': win->z += 1.0;
break;
case 'z': win->z -= 1.0;
break;
case 'Z':
win->zoom *= 1.1;
calc_win_props(win, NULL, NULL);
break;
case 'z':
win->zoom /= 1.1;
calc_win_props(win, NULL, NULL);
break;
// case 'h': createWindow(&SubWindow);
// break;
}
@@ -60,10 +68,28 @@ void keySpPressed(_U_ int key, _U_ int x, _U_ int y){
DBG("Sp. key pressed. mod=%d, keycode=%d, point=(%d,%d)\n", glutGetModifiers(), key, x,y);
}
void mousePressed(int _U_ key, int _U_ state, _U_ int x, _U_ int y){
// GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, GLUT_RIGHT_BUTTON
DBG("Mouse button %s. point=(%d, %d); mod=%d, button=%d\n",
(state == GLUT_DOWN)? "pressed":"released", x, y, glutGetModifiers(), key);
int oldx, oldy; // coordinates when mouse was pressed
int movingwin = 0; // ==1 when user moves image by middle button
void mousePressed(_U_ int key, _U_ int state, _U_ int x, _U_ int y){
// key: GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, GLUT_RIGHT_BUTTON
// state: GLUT_UP, GLUT_DOWN
int window = glutGetWindow();
windowData *win = searchWindow_byGLID(window);
if(!win) return;
if(state == GLUT_DOWN){
oldx = x; oldy = y;
float X,Y;
conv_mouse_to_image_coords(x,y,&X,&Y,win);
DBG("press in (%d, %d) == (%f, %f) on image", x,y,X,Y);
if(key == GLUT_MIDDLE_BUTTON) movingwin = 1;
if(key == 3){ // wheel UP
}else if(key == 4){ // wheel DOWN
}
}else{
movingwin = 0;
}
/* DBG("Mouse button %s. point=(%d, %d); mod=%d, button=%d\n",
(state == GLUT_DOWN)? "pressed":"released", x, y, glutGetModifiers(), key);*/
/* int window = glutGetWindow();
if(window == WaveWindow){ // ÝÅÌËÎÕÌÉ × ÏËÎÅ Ó ×ÅÊ×ÌÅÔÏÍ
@@ -76,9 +102,36 @@ void mousePressed(int _U_ key, int _U_ state, _U_ int x, _U_ int y){
}
*/
}
/* this doesn't work
void mouseWheel(int button, int dir, int x, int y){
int window = glutGetWindow();
windowData *win = searchWindow_byGLID(window);
if(!win) return;
DBG("Mouse wheel, dir: %d. point=(%d, %d); mod=%d, button=%d\n",
dir, x, y, glutGetModifiers(), button);
}
*/
void mouseMove(_U_ int x, _U_ int y){
DBG("Mouse moved to (%d, %d)\n", x, y);
int window = glutGetWindow();
windowData *win = searchWindow_byGLID(window);
if(!win) return;
//DBG("Mouse moved to (%d, %d)\n", x, y);
if(movingwin){
float X, Y, nx, ny, w2, h2;
float a = win->Daspect;
X = (x - oldx) * a; Y = (y - oldy) * a;
nx = win->x + X;
ny = win->y - Y;
w2 = win->image->w / 2. * win->zoom;
h2 = win->image->h / 2. * win->zoom;
if(nx < w2 && nx > -w2)
win->x = nx;
if(ny < h2 && ny > -h2)
win->y = ny;
oldx = x;
oldy = y;
calc_win_props(win, NULL, NULL);
}
}
/**