Fix detection of i386 in tmpi
[gromacs/AngularHB.git] / src / ngmx / buttons.c
bloba4f12e3003ddf36408561d680055ab66cac1a500
1 /*
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-2004, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012,2013, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
42 #include <sysstuff.h>
43 #include <string.h>
44 #include <smalloc.h>
45 #include <macros.h>
46 #include <x11.h>
47 #include <xutil.h>
48 #include "buttons.h"
49 #include "stop_ani.bm"
50 #include "play.bm"
51 #include "ff.bm"
52 #include "rewind.bm"
54 static void move_bbox(t_x11 *x11, t_butbox *bbox)
56 int x0, y0;
57 int i, bw;
58 real idb, bh;
59 t_windata *wd;
61 bw = max(1, bbox->wd.width-2*(AIR+BORDER));
62 idb = bbox->nbut;
63 bh = (bbox->wd.height-AIR*(bbox->nbut+1));
64 bh /= idb;
65 bh = max(bh, 1.0);
67 x0 = AIR;
68 y0 = AIR;
69 for (i = 0; (i < bbox->nbut); i++)
71 wd = &(bbox->b[i].wd);
72 wd->width = bw;
73 wd->height = bh;
74 wd->color = WHITE;
75 XMoveWindow(x11->disp, wd->self, x0, y0);
76 XResizeWindow(x11->disp, wd->self, wd->width, wd->height);
77 y0 += AIR+bh;
81 static gmx_bool BBCallBack(t_x11 *x11, XEvent *event, Window w, void *data)
83 t_butbox *bbox;
85 if (event->type == ConfigureNotify)
87 bbox = (t_butbox *)data;
88 bbox->wd.width = event->xconfigure.width;
89 bbox->wd.height = event->xconfigure.height;
90 move_bbox(x11, bbox);
92 return FALSE;
95 static gmx_bool VBCallBack(t_x11 *x11, XEvent *event, Window w, void *data)
97 t_butbox *vbox;
98 int y0;
100 if (event->type == Expose)
102 vbox = (t_butbox *)data;
103 y0 = XTextHeight(x11->font)+2*AIR+1;
104 XSetForeground(x11->disp, x11->gc, WHITE);
105 XClearArea(x11->disp, vbox->wd.self, 1, 1, vbox->wd.width-2, y0-1, False);
106 TextInRect(x11, vbox->wd.self, vbox->wd.text,
107 1, 1, vbox->wd.width-2, y0-1, eXLeft, eYCenter);
108 XDrawLine(x11->disp, vbox->wd.self, x11->gc, 0, y0, vbox->wd.width, y0);
109 XSetForeground(x11->disp, x11->gc, x11->fg);
111 return FALSE;
114 void set_vbtime(t_x11 *x11, t_butbox *vbox, char *text)
116 sfree(vbox->wd.text);
117 vbox->wd.text = strdup(text);
118 ExposeWin(x11->disp, vbox->wd.self);
121 static gmx_bool ButtonCallBack(t_x11 *x11, XEvent *event, Window w, void *data)
123 XEvent letter;
124 t_mwbut *but;
125 t_windata *wd;
127 but = (t_mwbut *)data;
128 wd = &(but->wd);
129 switch (event->type)
131 case Expose:
132 XSetForeground(x11->disp, x11->gc, WHITE);
133 XDrawRoundRect(x11->disp, wd->self, x11->gc,
134 0, 0, wd->width-1, wd->height-1);
135 TextInWin(x11, wd, wd->text, eXCenter, eYCenter);
136 XSetForeground(x11->disp, x11->gc, x11->fg);
137 break;
139 case EnterNotify:
140 /* LightBorder(x11->disp,wd->self,WHITE);*/
141 XSetForeground(x11->disp, x11->gc, WHITE);
142 XDrawRoundRect(x11->disp, wd->self, x11->gc,
143 1, 1, wd->width-3, wd->height-3);
144 XSetForeground(x11->disp, x11->gc, x11->fg);
145 break;
146 case LeaveNotify:
147 /* LightBorder(x11->disp,wd->self,BLUE);*/
148 XSetForeground(x11->disp, x11->gc, BLUE);
149 XDrawRoundRect(x11->disp, wd->self, x11->gc,
150 1, 1, wd->width-3, wd->height-3);
151 XSetForeground(x11->disp, x11->gc, x11->fg);
153 break;
155 case ButtonPress:
156 letter.type = ClientMessage;
157 letter.xclient.display = x11->disp;
158 letter.xclient.window = wd->Parent;
159 letter.xclient.message_type = 0;
160 letter.xclient.format = 32;
161 letter.xclient.data.l[0] = but->ID;
162 letter.xclient.data.l[1] = (long)event->xbutton.button;
163 XSendEvent(x11->disp, wd->Parent, True, 0, &letter);
164 break;
165 default:
166 break;
168 return FALSE;
171 t_butbox *init_vbox(t_x11 *x11, Window Parent, Window SendTo, unsigned long fg, unsigned long bg)
173 Pixmap pm;
174 unsigned char *data;
175 t_butbox *vb;
176 int i, ID, x, y0;
178 snew(vb, 1);
179 vb->nbut = IDNR-IDBUTNR-1;
180 snew(vb->b, vb->nbut);
182 /* VBox holder */
183 y0 = XTextHeight(x11->font)+2*AIR+2;
184 InitWin(&vb->wd, 0, 0, vb->nbut*(play_width+AIR)+AIR,
185 y0+play_height+2*AIR, 1, "VCR - Control");
186 vb->wd.self = XCreateSimpleWindow(x11->disp, Parent,
187 vb->wd.x, vb->wd.y, vb->wd.width, vb->wd.height,
188 vb->wd.bwidth, WHITE, BLACK);
189 x11->RegisterCallback(x11, vb->wd.self, Parent, VBCallBack, vb);
190 x11->SetInputMask(x11, vb->wd.self, ExposureMask);
192 x = AIR;
193 (void)CWBackPixmap;
194 for (i = 0; (i < vb->nbut); i++)
196 ID = IDBUTNR+i+1;
197 switch (ID)
199 case IDREWIND:
200 data = &(rewind_bits[0]);
201 break;
202 case IDSTEP:
203 data = play_bits;
204 break;
205 case IDFF:
206 data = ff_bits;
207 break;
208 case IDSTOP_ANI:
209 data = stop_ani_bits;
210 break;
211 default:
212 fprintf(stderr, "Invalid bitmap in init_vbox %d\n", ID);
213 exit(1);
215 /* Rely on the fact that all bitmaps are equal size */
216 pm = XCreatePixmapFromBitmapData(x11->disp, x11->root,
217 (char *)data, play_width, play_height,
218 BLACK, LIGHTGREY, x11->depth);
219 vb->b[i].ID = ID;
220 vb->b[i].wd.Parent = SendTo;
221 vb->b[i].wd.self =
222 XCreateSimpleWindow(x11->disp, vb->wd.self,
223 x, y0+AIR, play_width, play_height, 0, WHITE, BLACK);
224 XSetWindowBackgroundPixmap(x11->disp, vb->b[i].wd.self, pm);
226 x11->RegisterCallback(x11, vb->b[i].wd.self, vb->wd.self,
227 ButtonCallBack, &(vb->b[i]));
228 x11->SetInputMask(x11, vb->b[i].wd.self,
229 ButtonPressMask | StructureNotifyMask);
230 x += play_width+AIR;
233 return vb;
236 void show_but(t_x11 *x11, t_butbox *bbox)
238 XMapWindow(x11->disp, bbox->wd.self);
239 XMapSubwindows(x11->disp, bbox->wd.self);
242 void hide_but(t_x11 *x11, t_butbox *bbox)
244 XUnmapWindow(x11->disp, bbox->wd.self);
245 XUnmapSubwindows(x11->disp, bbox->wd.self);
248 t_butbox *init_bbox(t_x11 *x11, Window Parent, Window SendTo,
249 int width, unsigned long fg, unsigned long bg)
251 t_butbox *bbox;
252 static const char *lbut[IDBUTNR] = {
253 "< X-Rotate >", "< Y-Rotate >", "< Z-Rotate >",
254 "< X-Move >", "< Y-Move >", "< Z-Move >", "< Scale >",
256 int i, y0, h0;
257 t_mwbut *but;
258 Window DrawOn;
260 snew(bbox, 1);
261 bbox->nbut = IDBUTNR;
262 snew(bbox->b, bbox->nbut);
263 y0 = XTextHeight(x11->font)+2*(AIR+BORDER);
265 InitWin(&(bbox->wd), 0, 0, /*width,(y0+AIR)*IDBUTNR+AIR+2*BORDER,*/ 1, 1,
266 1, "Button Box");
267 width -= 2*AIR+2*BORDER;
268 bbox->wd.self = XCreateSimpleWindow(x11->disp, Parent,
269 bbox->wd.x, bbox->wd.y, bbox->wd.width,
270 bbox->wd.height, bbox->wd.bwidth,
271 fg, bg);
272 x11->RegisterCallback(x11, bbox->wd.self, Parent, BBCallBack, bbox);
273 x11->SetInputMask(x11, bbox->wd.self, StructureNotifyMask);
275 DrawOn = bbox->wd.self;
276 h0 = AIR;
277 for (i = 0; (i < bbox->nbut); i++)
279 but = &(bbox->b[i]);
280 InitWin(&but->wd, AIR, h0, width, y0, 1, lbut[i]);
281 h0 += y0+AIR;
282 but->wd.Parent = SendTo;
283 but->ID = i;
284 but->wd.self = XCreateSimpleWindow(x11->disp, DrawOn,
285 but->wd.x, but->wd.y,
286 but->wd.width, but->wd.height,
287 but->wd.bwidth, bg, bg);
288 x11->RegisterCallback(x11, but->wd.self, DrawOn, ButtonCallBack, but);
289 x11->SetInputMask(x11, but->wd.self, ExposureMask | ButtonPressMask |
290 EnterLeave);
292 return bbox;
295 void done_bbox(t_x11 *x11, t_butbox *bbox)
297 int i;
299 for (i = 0; (i < bbox->nbut); i++)
301 x11->UnRegisterCallback(x11, bbox->b[i].wd.self);
303 x11->UnRegisterCallback(x11, bbox->wd.self);
304 sfree(bbox->b);
305 sfree(bbox);