image view works!

This commit is contained in:
eddyem
2015-03-02 14:00:26 +03:00
parent 4e5d015e53
commit da3cde5816
10 changed files with 313 additions and 193 deletions

View File

@@ -21,35 +21,22 @@
#include "events.h"
#include "imageview.h"
#include "macros.h"
/*
* æÕÎËÃÉÉ ÄÌÑ ÒÁÂÏÔÙ Ó OpenGL'ÎÙÍÉ ÓÏÂÙÔÉÑÍÉ
/**
* manage pressed keys & menu items
*/
int ShowWavelet = 0;
void keyPressed(unsigned char key, // ËÏÄ ××ÅÄÅÎÎÏÇÏ ÓÉÍ×ÏÌÁ
_U_ int x, _U_ int y){ // ËÏÏÒÄÉÎÁÔÙ ÍÙÛÉ ÐÒÉ ÎÁÖÁÔÉÉ ËÌÁ×ÉÛÉ
int _U_ mod = glutGetModifiers(), window = glutGetWindow();
windowData *win = searchWindow_byGLID(window);
void processKeybrd(unsigned char key, int mod, int win_GL_ID, _U_ int x, _U_ int y){
windowData *win = searchWindow_byGLID(win_GL_ID);
if(!win) return;
//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("zoom = %f\n", win->zoom);
case 27:
destroyWindow_async(win_GL_ID);
break;
// case 'm': createWindow(&mainWindow);
// break;
// case 'w': createWindow(&WaveWindow);
// break;
case 'Z':
win->zoom *= 1.1;
calc_win_props(win, NULL, NULL);
@@ -58,11 +45,22 @@ void keyPressed(unsigned char key, //
win->zoom /= 1.1;
calc_win_props(win, NULL, NULL);
break;
// case 'h': createWindow(&SubWindow);
// break;
}
}
/*
* Process keyboard
*/
void keyPressed(unsigned char key,
_U_ int x, _U_ int y){
int mod = glutGetModifiers();
int window = glutGetWindow();
//mod: GLUT_ACTIVE_SHIFT, GLUT_ACTIVE_CTRL, GLUT_ACTIVE_ALT; result is their sum
//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
processKeybrd(key, mod, window, x, y);
}
void keySpPressed(_U_ int key, _U_ int x, _U_ int y){
// int mod = glutGetModifiers();
DBG("Sp. key pressed. mod=%d, keycode=%d, point=(%d,%d)\n", glutGetModifiers(), key, x,y);
@@ -73,18 +71,25 @@ 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();
int window = glutGetWindow(), mod = glutGetModifiers();
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);
DBG("press in (%d, %d) == (%f, %f) on image; mod == %d", x,y,X,Y, mod);
if(key == GLUT_MIDDLE_BUTTON) movingwin = 1;
if(key == 3){ // wheel UP
if(mod == 0) win->y += 10.*win->zoom; // nothing pressed - scroll up
else if(mod == GLUT_ACTIVE_SHIFT) win->x -= 10.*win->zoom; // shift pressed - scroll left
else if(mod == GLUT_ACTIVE_CTRL) win->zoom *= 1.1; // ctrl+wheel up == zoom+
}else if(key == 4){ // wheel DOWN
if(mod == 0) win->y -= 10.*win->zoom; // nothing pressed - scroll down
else if(mod == GLUT_ACTIVE_SHIFT) win->x += 10.*win->zoom; // shift pressed - scroll right
else if(mod == GLUT_ACTIVE_CTRL) win->zoom /= 1.1; // ctrl+wheel down == zoom-
}
calc_win_props(win, NULL, NULL);
}else{
movingwin = 0;
}
@@ -134,21 +139,27 @@ void mouseMove(_U_ int x, _U_ int y){
}
}
void menuEvents(int opt){
FNAME();
int window = glutGetWindow();
if(opt == 'q') exit(0);
processKeybrd((unsigned char)opt, 0, window, 0, 0);
}
/**
* winID - inner !!!
*/
void createMenu(_U_ int winID){
glutCreateMenu(menuEvents);
void createMenu(int GL_ID){
FNAME();
windowData *win;
win = searchWindow_byGLID(GL_ID);
glutSetWindow(GL_ID);
if(win->menu) glutDestroyMenu(win->menu);
win->menu = glutCreateMenu(menuEvents);
DBG("created menu %d\n", win->menu);
glutAddMenuEntry("Quit (ctrl+q)", 'q');
glutAddMenuEntry("Close this window (ESC)", 27);
// if(window == &mainWindow){ // ÐÕÎËÔÙ ÍÅÎÀ ÇÌÁ×ÎÏÇÏ ÏËÎÁ
glutAddMenuEntry("Info in stderr (i)", 'i');
// }
;
glutAddMenuEntry("Restore zoom (1)", '1');
glutAttachMenu(GLUT_RIGHT_BUTTON);
}
void menuEvents(int opt){
if(opt == 'q') exit(0);
keyPressed((unsigned char)opt, 0, 0);
}