changed reading hint
[gromacs/adressmacs.git] / src / ngmx / buttons.c
blob1cc41b229d6d0da99129a42da9c804422715c12f
1 /*
2 * $Id$
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 2.0
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
16 * Please refer to:
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
23 * or e-mail to:
24 * gromacs@chem.rug.nl
26 * And Hey:
27 * Great Red Oystrich Makes All Chemists Sane
29 static char *SRCID_buttons_c = "$Id$";
31 #include <sysstuff.h>
32 #include <string.h>
33 #include <smalloc.h>
34 #include <macros.h>
35 #include <x11.h>
36 #include <xutil.h>
37 #include "buttons.h"
38 #include "stop_ani.bm"
39 #include "play.bm"
40 #include "ff.bm"
41 #include "rewind.bm"
43 static void move_bbox(t_x11 *x11,t_butbox *bbox)
45 int x0,y0;
46 int i,bw;
47 real idb,bh;
48 t_windata *wd;
50 bw=max(1,bbox->wd.width-2*(AIR+BORDER));
51 idb=bbox->nbut;
52 bh=(bbox->wd.height-AIR*(bbox->nbut+1));
53 bh/=idb;
54 bh=max(bh,1.0);
56 x0=AIR;
57 y0=AIR;
58 for (i=0; (i<bbox->nbut); i++) {
59 wd=&(bbox->b[i].wd);
60 wd->width=bw;
61 wd->height=bh;
62 wd->color = WHITE;
63 XMoveWindow(x11->disp,wd->self,x0,y0);
64 XResizeWindow(x11->disp,wd->self,wd->width,wd->height);
65 y0+=AIR+bh;
69 static bool BBCallBack(t_x11 *x11,XEvent *event, Window w,void *data)
71 t_butbox *bbox;
73 if (event->type==ConfigureNotify) {
74 bbox=(t_butbox *)data;
75 bbox->wd.width=event->xconfigure.width;
76 bbox->wd.height=event->xconfigure.height;
77 move_bbox(x11,bbox);
79 return FALSE;
82 static bool VBCallBack(t_x11 *x11,XEvent *event, Window w,void *data)
84 t_butbox *vbox;
85 int y0;
87 if (event->type==Expose) {
88 vbox=(t_butbox *)data;
89 y0=XTextHeight(x11->font)+2*AIR+1;
90 XSetForeground(x11->disp,x11->gc,WHITE);
91 XClearArea(x11->disp,vbox->wd.self,1,1,vbox->wd.width-2,y0-1,False);
92 TextInRect(x11,vbox->wd.self,vbox->wd.text,
93 1,1,vbox->wd.width-2,y0-1,eXLeft,eYCenter);
94 XDrawLine(x11->disp,vbox->wd.self,x11->gc,0,y0,vbox->wd.width,y0);
95 XSetForeground(x11->disp,x11->gc,x11->fg);
97 return FALSE;
100 void set_vbtime(t_x11 *x11,t_butbox *vbox,char *text)
102 sfree(vbox->wd.text);
103 vbox->wd.text=strdup(text);
104 ExposeWin(x11->disp,vbox->wd.self);
107 static bool ButtonCallBack(t_x11 *x11,XEvent *event, Window w, void *data)
109 XEvent letter;
110 t_mwbut *but;
111 t_windata *wd;
113 but=(t_mwbut *)data;
114 wd=&(but->wd);
115 switch(event->type) {
116 case Expose:
117 XSetForeground(x11->disp,x11->gc,WHITE);
118 XDrawRoundRect(x11->disp, wd->self, x11->gc,
119 0,0,wd->width-1,wd->height-1);
120 TextInWin(x11,wd,wd->text,eXCenter,eYCenter);
121 XSetForeground(x11->disp,x11->gc,x11->fg);
122 break;
124 case EnterNotify:
125 /* LightBorder(x11->disp,wd->self,WHITE);*/
126 XSetForeground(x11->disp,x11->gc,WHITE);
127 XDrawRoundRect(x11->disp, wd->self, x11->gc,
128 1,1,wd->width-3,wd->height-3);
129 XSetForeground(x11->disp,x11->gc,x11->fg);
130 break;
131 case LeaveNotify:
132 /* LightBorder(x11->disp,wd->self,BLUE);*/
133 XSetForeground(x11->disp,x11->gc,BLUE);
134 XDrawRoundRect(x11->disp, wd->self, x11->gc,
135 1,1,wd->width-3,wd->height-3);
136 XSetForeground(x11->disp,x11->gc,x11->fg);
138 break;
140 case ButtonPress:
141 letter.type=ClientMessage;
142 letter.xclient.display=x11->disp;
143 letter.xclient.window=wd->Parent;
144 letter.xclient.message_type=0;
145 letter.xclient.format=32;
146 letter.xclient.data.l[0]=but->ID;
147 letter.xclient.data.l[1]=(long)event->xbutton.button;
148 XSendEvent(x11->disp,wd->Parent,True,0,&letter);
149 break;
150 default:
151 break;
153 return FALSE;
156 t_butbox *init_vbox(t_x11 *x11,Window Parent,Window SendTo,unsigned long fg,unsigned long bg)
158 Pixmap pm;
159 unsigned char *data;
160 t_butbox *vb;
161 int i,ID,x,y0;
163 snew(vb,1);
164 vb->nbut=IDNR-IDBUTNR-1;
165 snew(vb->b,vb->nbut);
167 /* VBox holder */
168 y0=XTextHeight(x11->font)+2*AIR+2;
169 InitWin(&vb->wd,0,0,vb->nbut*(play_width+AIR)+AIR,
170 y0+play_height+2*AIR,1,"VCR - Control");
171 vb->wd.self=XCreateSimpleWindow(x11->disp,Parent,
172 vb->wd.x,vb->wd.y,vb->wd.width,vb->wd.height,
173 vb->wd.bwidth,WHITE,BLACK);
174 x11->RegisterCallback(x11,vb->wd.self,Parent,VBCallBack,vb);
175 x11->SetInputMask(x11,vb->wd.self,ExposureMask);
177 x=AIR;
178 (void)CWBackPixmap;
179 for(i=0; (i<vb->nbut); i++) {
180 ID=IDBUTNR+i+1;
181 switch (ID) {
182 case IDREWIND:
183 data=&(rewind_bits[0]);
184 break;
185 case IDSTEP:
186 data=play_bits;
187 break;
188 case IDFF:
189 data=ff_bits;
190 break;
191 case IDSTOP_ANI:
192 data=stop_ani_bits;
193 break;
194 default:
195 fprintf(stderr,"Invalid bitmap in init_vbox %d\n",ID);
196 exit(1);
198 /* Rely on the fact that all bitmaps are equal size */
199 pm=XCreatePixmapFromBitmapData(x11->disp,x11->root,
200 (char *)data,play_width,play_height,
201 BLACK,LIGHTGREY,x11->depth);
202 vb->b[i].ID=ID;
203 vb->b[i].wd.Parent=SendTo;
204 vb->b[i].wd.self=
205 XCreateSimpleWindow(x11->disp,vb->wd.self,
206 x,y0+AIR,play_width,play_height,0,WHITE,BLACK);
207 XSetWindowBackgroundPixmap(x11->disp,vb->b[i].wd.self,pm);
209 x11->RegisterCallback(x11,vb->b[i].wd.self,vb->wd.self,
210 ButtonCallBack,&(vb->b[i]));
211 x11->SetInputMask(x11,vb->b[i].wd.self,
212 ButtonPressMask | StructureNotifyMask);
213 x+=play_width+AIR;
216 return vb;
219 void show_but(t_x11 *x11,t_butbox *bbox)
221 XMapWindow(x11->disp,bbox->wd.self);
222 XMapSubwindows(x11->disp,bbox->wd.self);
225 void hide_but(t_x11 *x11,t_butbox *bbox)
227 XUnmapWindow(x11->disp,bbox->wd.self);
228 XUnmapSubwindows(x11->disp,bbox->wd.self);
231 t_butbox *init_bbox(t_x11 *x11,Window Parent,Window SendTo,
232 int width,unsigned long fg,unsigned long bg)
234 t_butbox *bbox;
235 static char *lbut[IDBUTNR] = {
236 "< X-Rotate >", "< Y-Rotate >", "< Z-Rotate >",
237 "< X-Move >", "< Y-Move >", "< Z-Move >", "< Scale >",
239 int i,y0,h0;
240 t_mwbut *but;
241 Window DrawOn;
243 snew(bbox,1);
244 bbox->nbut=IDBUTNR;
245 snew(bbox->b,bbox->nbut);
246 y0=XTextHeight(x11->font)+2*(AIR+BORDER);
248 InitWin(&(bbox->wd),0,0,/*width,(y0+AIR)*IDBUTNR+AIR+2*BORDER,*/1,1,
249 1,"Button Box");
250 width-=2*AIR+2*BORDER;
251 bbox->wd.self=XCreateSimpleWindow(x11->disp,Parent,
252 bbox->wd.x,bbox->wd.y,bbox->wd.width,
253 bbox->wd.height,bbox->wd.bwidth,
254 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;
259 h0=AIR;
260 for (i=0; (i<bbox->nbut); i++) {
261 but=&(bbox->b[i]);
262 InitWin(&but->wd,AIR,h0,width,y0,1,lbut[i]);
263 h0+=y0+AIR;
264 but->wd.Parent=SendTo;
265 but->ID=i;
266 but->wd.self=XCreateSimpleWindow(x11->disp,DrawOn,
267 but->wd.x,but->wd.y,
268 but->wd.width,but->wd.height,
269 but->wd.bwidth,bg,bg);
270 x11->RegisterCallback(x11,but->wd.self,DrawOn,ButtonCallBack,but);
271 x11->SetInputMask(x11,but->wd.self,ExposureMask | ButtonPressMask |
272 EnterLeave);
274 return bbox;
277 void done_bbox(t_x11 *x11,t_butbox *bbox)
279 int i;
281 for(i=0; (i<bbox->nbut); i++)
282 x11->UnRegisterCallback(x11,bbox->b[i].wd.self);
283 x11->UnRegisterCallback(x11,bbox->wd.self);
284 sfree(bbox->b);
285 sfree(bbox);