2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2013, The GROMACS development team.
6 * Copyright (c) 2013,2014, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
46 #include "gromacs/legacyheaders/macros.h"
47 #include "gromacs/utility/cstringutil.h"
48 #include "gromacs/utility/smalloc.h"
54 #include "stop_ani.bm"
59 static void move_bbox(t_x11 *x11, t_butbox *bbox)
63 real idb, bh, one = 1.0;
66 bw = std::max(1, bbox->wd.width-2*(AIR+BORDER));
68 bh = (bbox->wd.height-AIR*(bbox->nbut+1));
70 bh = std::max(bh, one);
74 for (i = 0; (i < bbox->nbut); i++)
76 wd = &(bbox->b[i].wd);
80 XMoveWindow(x11->disp, wd->self, x0, y0);
81 XResizeWindow(x11->disp, wd->self, wd->width, wd->height);
86 static bool BBCallBack(t_x11 *x11, XEvent *event, Window /*w*/, void *data)
90 if (event->type == ConfigureNotify)
92 bbox = (t_butbox *)data;
93 bbox->wd.width = event->xconfigure.width;
94 bbox->wd.height = event->xconfigure.height;
100 static bool VBCallBack(t_x11 *x11, XEvent *event, Window /*w*/, void *data)
105 if (event->type == Expose)
107 vbox = (t_butbox *)data;
108 y0 = XTextHeight(x11->font)+2*AIR+1;
109 XSetForeground(x11->disp, x11->gc, WHITE);
110 XClearArea(x11->disp, vbox->wd.self, 1, 1, vbox->wd.width-2, y0-1, False);
111 TextInRect(x11, vbox->wd.self, vbox->wd.text,
112 1, 1, vbox->wd.width-2, y0-1, eXLeft, eYCenter);
113 XDrawLine(x11->disp, vbox->wd.self, x11->gc, 0, y0, vbox->wd.width, y0);
114 XSetForeground(x11->disp, x11->gc, x11->fg);
119 void set_vbtime(t_x11 *x11, t_butbox *vbox, char *text)
121 sfree(vbox->wd.text);
122 vbox->wd.text = gmx_strdup(text);
123 ExposeWin(x11->disp, vbox->wd.self);
126 static bool ButtonCallBack(t_x11 *x11, XEvent *event, Window /*w*/, void *data)
132 but = (t_mwbut *)data;
137 XSetForeground(x11->disp, x11->gc, WHITE);
138 XDrawRoundRect(x11->disp, wd->self, x11->gc,
139 0, 0, wd->width-1, wd->height-1);
140 TextInWin(x11, wd, wd->text, eXCenter, eYCenter);
141 XSetForeground(x11->disp, x11->gc, x11->fg);
145 /* LightBorder(x11->disp,wd->self,WHITE);*/
146 XSetForeground(x11->disp, x11->gc, WHITE);
147 XDrawRoundRect(x11->disp, wd->self, x11->gc,
148 1, 1, wd->width-3, wd->height-3);
149 XSetForeground(x11->disp, x11->gc, x11->fg);
152 /* LightBorder(x11->disp,wd->self,BLUE);*/
153 XSetForeground(x11->disp, x11->gc, BLUE);
154 XDrawRoundRect(x11->disp, wd->self, x11->gc,
155 1, 1, wd->width-3, wd->height-3);
156 XSetForeground(x11->disp, x11->gc, x11->fg);
161 letter.type = ClientMessage;
162 letter.xclient.display = x11->disp;
163 letter.xclient.window = wd->Parent;
164 letter.xclient.message_type = 0;
165 letter.xclient.format = 32;
166 letter.xclient.data.l[0] = but->ID;
167 letter.xclient.data.l[1] = (long)event->xbutton.button;
168 XSendEvent(x11->disp, wd->Parent, True, 0, &letter);
176 t_butbox *init_vbox(t_x11 *x11, Window Parent, Window SendTo, unsigned long fg, unsigned long bg)
184 vb->nbut = IDNR-IDBUTNR-1;
185 snew(vb->b, vb->nbut);
188 y0 = XTextHeight(x11->font)+2*AIR+2;
189 InitWin(&vb->wd, 0, 0, vb->nbut*(play_width+AIR)+AIR,
190 y0+play_height+2*AIR, 1, "VCR - Control");
191 vb->wd.self = XCreateSimpleWindow(x11->disp, Parent,
192 vb->wd.x, vb->wd.y, vb->wd.width, vb->wd.height,
193 vb->wd.bwidth, fg, bg);
194 x11->RegisterCallback(x11, vb->wd.self, Parent, VBCallBack, vb);
195 x11->SetInputMask(x11, vb->wd.self, ExposureMask);
199 for (i = 0; (i < vb->nbut); i++)
205 data = &(rewind_bits[0]);
214 data = stop_ani_bits;
217 fprintf(stderr, "Invalid bitmap in init_vbox %d\n", ID);
220 /* Rely on the fact that all bitmaps are equal size */
221 pm = XCreatePixmapFromBitmapData(x11->disp, x11->root,
222 (char *)data, play_width, play_height,
223 BLACK, LIGHTGREY, x11->depth);
225 vb->b[i].wd.Parent = SendTo;
227 XCreateSimpleWindow(x11->disp, vb->wd.self,
228 x, y0+AIR, play_width, play_height, 0, WHITE, BLACK);
229 XSetWindowBackgroundPixmap(x11->disp, vb->b[i].wd.self, pm);
231 x11->RegisterCallback(x11, vb->b[i].wd.self, vb->wd.self,
232 ButtonCallBack, &(vb->b[i]));
233 x11->SetInputMask(x11, vb->b[i].wd.self,
234 ButtonPressMask | StructureNotifyMask);
241 void show_but(t_x11 *x11, t_butbox *bbox)
243 XMapWindow(x11->disp, bbox->wd.self);
244 XMapSubwindows(x11->disp, bbox->wd.self);
247 void hide_but(t_x11 *x11, t_butbox *bbox)
249 XUnmapWindow(x11->disp, bbox->wd.self);
250 XUnmapSubwindows(x11->disp, bbox->wd.self);
253 t_butbox *init_bbox(t_x11 *x11, Window Parent, Window SendTo,
254 int width, unsigned long fg, unsigned long bg)
257 static const char *lbut[IDBUTNR] = {
258 "< X-Rotate >", "< Y-Rotate >", "< Z-Rotate >",
259 "< X-Move >", "< Y-Move >", "< Z-Move >", "< Scale >",
266 bbox->nbut = IDBUTNR;
267 snew(bbox->b, bbox->nbut);
268 y0 = XTextHeight(x11->font)+2*(AIR+BORDER);
270 InitWin(&(bbox->wd), 0, 0, /*width,(y0+AIR)*IDBUTNR+AIR+2*BORDER,*/ 1, 1,
272 width -= 2*AIR+2*BORDER;
273 bbox->wd.self = XCreateSimpleWindow(x11->disp, Parent,
274 bbox->wd.x, bbox->wd.y, bbox->wd.width,
275 bbox->wd.height, bbox->wd.bwidth,
277 x11->RegisterCallback(x11, bbox->wd.self, Parent, BBCallBack, bbox);
278 x11->SetInputMask(x11, bbox->wd.self, StructureNotifyMask);
280 DrawOn = bbox->wd.self;
282 for (i = 0; (i < bbox->nbut); i++)
285 InitWin(&but->wd, AIR, h0, width, y0, 1, lbut[i]);
287 but->wd.Parent = SendTo;
289 but->wd.self = XCreateSimpleWindow(x11->disp, DrawOn,
290 but->wd.x, but->wd.y,
291 but->wd.width, but->wd.height,
292 but->wd.bwidth, bg, bg);
293 x11->RegisterCallback(x11, but->wd.self, DrawOn, ButtonCallBack, but);
294 x11->SetInputMask(x11, but->wd.self, ExposureMask | ButtonPressMask |
300 void done_bbox(t_x11 *x11, t_butbox *bbox)
304 for (i = 0; (i < bbox->nbut); i++)
306 x11->UnRegisterCallback(x11, bbox->b[i].wd.self);
308 x11->UnRegisterCallback(x11, bbox->wd.self);