1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
|
/*******************************************************************************
* *
* Viewmol *
* *
* Z O O M . C *
* *
* Copyright (c) Joerg-R. Hill, October 2003 *
* *
********************************************************************************
*
* $Id: zoom.c,v 1.6 2003/11/07 11:17:44 jrh Exp $
* $Log: zoom.c,v $
* Revision 1.6 2003/11/07 11:17:44 jrh
* Release 2.4
*
* Revision 1.5 2000/12/10 15:19:37 jrh
* Release 2.3
*
* Revision 1.4 1999/05/24 01:28:10 jrh
* Release 2.2.1
*
* Revision 1.3 1999/02/07 22:00:33 jrh
* Release 2.2
*
* Revision 1.2 1998/01/26 00:49:55 jrh
* Release 2.1
*
* Revision 1.1 1996/12/10 18:44:37 jrh
* Initial revision
*
*/
#include<X11/Xlib.h>
#include<X11/Intrinsic.h>
#include<Xm/DrawingA.h>
#include "viewmol.h"
extern void drawSpectrum(Widget, caddr_t, caddr_t);
extern void drawMODiagram(Widget, caddr_t, caddr_t);
extern void setWindowColor(int, Pixel, const float *);
extern void pixelToWorld(int, double *, double *);
extern void *getmem(size_t, size_t);
extern void *expmem(void *, size_t, size_t);
extern void fremem(void **);
extern void setMenuItem(int, int);
extern void redraw(int);
extern struct WINDOW windows[];
extern struct MOLECULE *molecules;
extern int swapBuffers, nbasfu;
static int mouseInitX, mouseInitY, window, zoomRec=0;
static struct ZOOM *zoomOld=NULL;
void zoomIn(Widget widget, XmDrawingAreaCallbackStruct *data)
{
/* This subroutine is called when the user wants to zoom
into the spectrum or into the MO diagram. It is called
when the middle mouse button is held down and the mouse
is moved. */
Dimension width, height;
swapBuffers=FALSE;
if (widget == windows[SPECTRUM].widget)
{
drawSpectrum((Widget)0, (caddr_t)0, (caddr_t)0);
window=SPECTRUM;
}
else if (widget == windows[MO].widget)
{
drawMODiagram((Widget)0, (caddr_t)0, (caddr_t)0);
window=MO;
}
swapBuffers=TRUE;
XtVaGetValues(windows[window].widget, XmNwidth, &width, XmNheight, &height, NULL);
glEnable(GL_LINE_STIPPLE); /* Dotted lines */
glLineStipple(1, 0x5555);
glLineWidth((GLfloat)1.);
setWindowColor(FOREGROUND, windows[window].foreground, windows[window].foreground_rgb);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0, (double)width, 0.0, (double)height, 0.0, 1.0);
glBegin(GL_LINE_LOOP);
glVertex2i(mouseInitX, mouseInitY);
glVertex2i(mouseInitX, height-data->event->xmotion.y);
glVertex2i(data->event->xmotion.x, height-data->event->xmotion.y);
glVertex2i(data->event->xmotion.x, mouseInitY);
glEnd();
glDisable(GL_LINE_STIPPLE);
glXSwapBuffers(XtDisplay(widget), XtWindow(widget));
glPopMatrix();
}
void initZoom(Widget widget, XmDrawingAreaCallbackStruct *data)
{
Dimension height;
XtVaGetValues(widget, XmNheight, &height, NULL);
mouseInitX=data->event->xbutton.x;
mouseInitY=height-data->event->xbutton.y;
}
void saveZoom(int window)
{
if (zoomOld == NULL)
zoomOld=(struct ZOOM *)getmem(zoomRec+1, sizeof(struct ZOOM));
else
zoomOld=(struct ZOOM *)expmem((void *)zoomOld, zoomRec+1, sizeof(struct ZOOM));
zoomOld[zoomRec].window=window;
zoomOld[zoomRec].left=windows[window].left;
zoomOld[zoomRec].right=windows[window].right;
zoomOld[zoomRec].bottom=windows[window].bottom;
zoomOld[zoomRec++].top=windows[window].top;
}
void endZoom(Widget widget, int x, int y)
{
Dimension height;
double xpix, ypix, save;
/* Copy final values and be careful that these are not
equal to the start values. */
pixelToWorld(window, &xpix, &ypix);
XtVaGetValues(widget, XmNheight, &height, NULL);
saveZoom(window);
if (window == SPECTRUM)
{
save=windows[window].left;
if (mouseInitX < x)
{
windows[window].left=(mouseInitX-windows[window].horizontalMargin)*xpix+save;
windows[window].right=(x-windows[window].horizontalMargin)*xpix+save;
}
else if (mouseInitX == x)
{
windows[window].left=(mouseInitX-windows[window].horizontalMargin)*xpix+save;
windows[window].right=(mouseInitX-windows[window].horizontalMargin+1)*xpix+save;
}
else
{
windows[window].left=(x-windows[window].horizontalMargin)*xpix+save;
windows[window].right=(mouseInitX-windows[window].horizontalMargin)*xpix+save;
}
}
y=height-y;
save=windows[window].bottom;
if (mouseInitY < y)
{
windows[window].top=(y-windows[window].verticalMargin)*ypix+save;
windows[window].bottom=(mouseInitY-windows[window].verticalMargin)*ypix+save;
}
else if (mouseInitY == y)
{
windows[window].top=(mouseInitY-windows[window].verticalMargin+1)*ypix+save;
windows[window].bottom=(mouseInitY-windows[window].verticalMargin)*ypix+save;
}
else
{
windows[window].top=(mouseInitY-windows[window].verticalMargin)*ypix+save;
windows[window].bottom=(y-windows[window].verticalMargin)*ypix+save;
}
if (window == SPECTRUM)
{
drawSpectrum((Widget)0, (caddr_t)0, (caddr_t)0);
setMenuItem(SPECTRUM_ZOOMOUT, True);
}
else if (window == MO)
{
drawMODiagram((Widget)0, (caddr_t)0, (caddr_t)0);
setMenuItem(MO_ZOOMOUT, True);
}
}
void zoomOut(Widget widget, caddr_t window, XmDrawingAreaCallbackStruct *data)
{
register int i, j, w;
w=(int)window;
for (i=zoomRec-1; i>=0; i--)
{
if (zoomOld[i].window == w)
{
windows[w].left=zoomOld[i].left;
windows[w].right=zoomOld[i].right;
windows[w].bottom=zoomOld[i].bottom;
windows[w].top=zoomOld[i].top;
for (j=i+1; j<zoomRec; j++)
{
zoomOld[i].window=zoomOld[j].window;
zoomOld[i].left=zoomOld[j].left;
zoomOld[i].right=zoomOld[j].right;
zoomOld[i].bottom=zoomOld[j].bottom;
zoomOld[i].top=zoomOld[j].top;
i++;
}
zoomRec--;
if (zoomRec == 0)
{
fremem((void **)&zoomOld);
switch (w)
{
case SPECTRUM: setMenuItem(SPECTRUM_ZOOMOUT, False);
break;
case MO: setMenuItem(MO_ZOOMOUT, False);
break;
}
}
else
zoomOld=(struct ZOOM *)expmem((void *)zoomOld, zoomRec, sizeof(struct ZOOM));
break;
}
}
redraw(w);
}
int checkZoom(int window)
{
struct MOLECULE *mol;
register int i, found=FALSE;
if (zoomRec == 0) return(FALSE);
for (i=0; i<zoomRec; i++)
{
if (zoomOld[i].window == window)
{
if (window == MO)
{
mol=&molecules[windows[MO].set];
zoomOld[i].bottom=1.05*mol->orbitals[0].energy;
zoomOld[i].top=1.05*mol->orbitals[mol->nbasfu-1].energy;
}
found=TRUE;
break;
}
}
return(found);
}
|