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,2015,2019,2020, 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/utility/cstringutil.h"
47 #include "gromacs/utility/smalloc.h"
52 #include "stop_ani.bm"
56 static void move_bbox(t_x11* x11, t_butbox* bbox)
60 real idb, bh, one = 1.0;
63 bw = std::max(1, bbox->wd.width - 2 * (AIR + BORDER));
65 bh = (bbox->wd.height - AIR * (bbox->nbut + 1));
67 bh = std::max(bh, one);
71 for (i = 0; (i < bbox->nbut); i++)
73 wd = &(bbox->b[i].wd);
77 XMoveWindow(x11->disp, wd->self, x0, y0);
78 XResizeWindow(x11->disp, wd->self, wd->width, wd->height);
83 static bool BBCallBack(t_x11* x11, XEvent* event, Window /*w*/, void* data)
87 if (event->type == ConfigureNotify)
89 bbox = (t_butbox*)data;
90 bbox->wd.width = event->xconfigure.width;
91 bbox->wd.height = event->xconfigure.height;
97 static bool VBCallBack(t_x11* x11, XEvent* event, Window /*w*/, void* data)
102 if (event->type == Expose)
104 vbox = (t_butbox*)data;
105 y0 = XTextHeight(x11->font) + 2 * AIR + 1;
106 XSetForeground(x11->disp, x11->gc, WHITE);
107 XClearArea(x11->disp, vbox->wd.self, 1, 1, vbox->wd.width - 2, y0 - 1, False);
108 TextInRect(x11, vbox->wd.self, vbox->wd.text, 1, 1, vbox->wd.width - 2, y0 - 1, eXLeft, eYCenter);
109 XDrawLine(x11->disp, vbox->wd.self, x11->gc, 0, y0, vbox->wd.width, y0);
110 XSetForeground(x11->disp, x11->gc, x11->fg);
115 void set_vbtime(t_x11* x11, t_butbox* vbox, char* text)
117 sfree(vbox->wd.text);
118 vbox->wd.text = gmx_strdup(text);
119 ExposeWin(x11->disp, vbox->wd.self);
122 static bool ButtonCallBack(t_x11* x11, XEvent* event, Window /*w*/, void* data)
128 but = (t_mwbut*)data;
133 XSetForeground(x11->disp, x11->gc, WHITE);
134 XDrawRoundRect(x11->disp, wd->self, x11->gc, 0, 0, wd->width - 1, wd->height - 1);
135 TextInWin(x11, wd, wd->text, eXCenter, eYCenter);
136 XSetForeground(x11->disp, x11->gc, x11->fg);
140 /* LightBorder(x11->disp,wd->self,WHITE);*/
141 XSetForeground(x11->disp, x11->gc, WHITE);
142 XDrawRoundRect(x11->disp, wd->self, x11->gc, 1, 1, wd->width - 3, wd->height - 3);
143 XSetForeground(x11->disp, x11->gc, x11->fg);
146 /* LightBorder(x11->disp,wd->self,BLUE);*/
147 XSetForeground(x11->disp, x11->gc, BLUE);
148 XDrawRoundRect(x11->disp, wd->self, x11->gc, 1, 1, wd->width - 3, wd->height - 3);
149 XSetForeground(x11->disp, x11->gc, x11->fg);
154 letter.type = ClientMessage;
155 letter.xclient.display = x11->disp;
156 letter.xclient.window = wd->Parent;
157 letter.xclient.message_type = 0;
158 letter.xclient.format = 32;
159 letter.xclient.data.l[0] = but->ID;
160 letter.xclient.data.l[1] = (long)event->xbutton.button;
161 XSendEvent(x11->disp, wd->Parent, True, 0, &letter);
168 t_butbox* init_vbox(t_x11* x11, Window Parent, Window SendTo, unsigned long fg, unsigned long bg)
176 vb->nbut = IDNR - IDBUTNR - 1;
177 snew(vb->b, vb->nbut);
180 y0 = XTextHeight(x11->font) + 2 * AIR + 2;
184 vb->nbut * (play_width + AIR) + AIR,
185 y0 + play_height + 2 * AIR,
188 vb->wd.self = XCreateSimpleWindow(
189 x11->disp, Parent, vb->wd.x, vb->wd.y, vb->wd.width, vb->wd.height, vb->wd.bwidth, fg, bg);
190 x11->RegisterCallback(x11, vb->wd.self, Parent, VBCallBack, vb);
191 x11->SetInputMask(x11, vb->wd.self, ExposureMask);
195 for (i = 0; (i < vb->nbut); i++)
197 ID = IDBUTNR + i + 1;
200 case IDREWIND: data = &(rewind_bits[0]); break;
201 case IDSTEP: data = play_bits; break;
202 case IDFF: data = ff_bits; break;
203 case IDSTOP_ANI: data = stop_ani_bits; break;
204 default: fprintf(stderr, "Invalid bitmap in init_vbox %d\n", ID); std::exit(1);
206 /* Rely on the fact that all bitmaps are equal size */
207 pm = XCreatePixmapFromBitmapData(
208 x11->disp, x11->root, (char*)data, play_width, play_height, BLACK, LIGHTGREY, x11->depth);
210 vb->b[i].wd.Parent = SendTo;
211 vb->b[i].wd.self = XCreateSimpleWindow(
212 x11->disp, vb->wd.self, x, y0 + AIR, play_width, play_height, 0, WHITE, BLACK);
213 XSetWindowBackgroundPixmap(x11->disp, vb->b[i].wd.self, pm);
215 x11->RegisterCallback(x11, vb->b[i].wd.self, vb->wd.self, ButtonCallBack, &(vb->b[i]));
216 x11->SetInputMask(x11, vb->b[i].wd.self, ButtonPressMask | StructureNotifyMask);
217 x += play_width + AIR;
223 void show_but(t_x11* x11, t_butbox* bbox)
225 XMapWindow(x11->disp, bbox->wd.self);
226 XMapSubwindows(x11->disp, bbox->wd.self);
229 void hide_but(t_x11* x11, t_butbox* bbox)
231 XUnmapWindow(x11->disp, bbox->wd.self);
232 XUnmapSubwindows(x11->disp, bbox->wd.self);
235 t_butbox* init_bbox(t_x11* x11, Window Parent, Window SendTo, int width, unsigned long fg, unsigned long bg)
238 static const char* lbut[IDBUTNR] = {
239 "< X-Rotate >", "< Y-Rotate >", "< Z-Rotate >", "< X-Move >",
240 "< Y-Move >", "< Z-Move >", "< Scale >",
247 bbox->nbut = IDBUTNR;
248 snew(bbox->b, bbox->nbut);
249 y0 = XTextHeight(x11->font) + 2 * (AIR + BORDER);
251 InitWin(&(bbox->wd), 0, 0, /*width,(y0+AIR)*IDBUTNR+AIR+2*BORDER,*/ 1, 1, 1, "Button Box");
252 width -= 2 * AIR + 2 * BORDER;
253 bbox->wd.self = XCreateSimpleWindow(
254 x11->disp, Parent, bbox->wd.x, bbox->wd.y, bbox->wd.width, bbox->wd.height, bbox->wd.bwidth, fg, bg);
255 x11->RegisterCallback(x11, bbox->wd.self, Parent, BBCallBack, bbox);
256 x11->SetInputMask(x11, bbox->wd.self, StructureNotifyMask);
258 DrawOn = bbox->wd.self;
260 for (i = 0; (i < bbox->nbut); i++)
263 InitWin(&but->wd, AIR, h0, width, y0, 1, lbut[i]);
265 but->wd.Parent = SendTo;
267 but->wd.self = XCreateSimpleWindow(
268 x11->disp, DrawOn, but->wd.x, but->wd.y, but->wd.width, but->wd.height, but->wd.bwidth, bg, bg);
269 x11->RegisterCallback(x11, but->wd.self, DrawOn, ButtonCallBack, but);
270 x11->SetInputMask(x11, but->wd.self, ExposureMask | ButtonPressMask | EnterLeave);
275 void done_bbox(t_x11* x11, t_butbox* bbox)
279 for (i = 0; (i < bbox->nbut); i++)
281 x11->UnRegisterCallback(x11, bbox->b[i].wd.self);
283 x11->UnRegisterCallback(x11, bbox->wd.self);