3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * Gyas ROwers Mature At Cryogenic Speed
50 t_windata wd
; /* Window structure */
51 int nlines
,top
; /* Number of lines, current top line */
52 char **lines
; /* The strings */
53 int wheight
,wwidth
; /* The size of the window in chars */
54 XFontStruct
*font
; /* Font */
55 unsigned long fg
,bg
; /* Colours */
58 static void calc_scrollw(t_scrollw
*sw
,int w
,int h
)
62 sw
->wheight
=h
/(YSPACE
+XTextHeight(sw
->font
));
63 sw
->wwidth
=w
/XTextWidth(sw
->font
,"W",1);
66 static bool SWCallback(t_x11
*x11
,XEvent
*event
,Window w
,void *data
)
69 int i
,y
,nl
,barw
,btop
,bheight
;
74 /* Calc some bar data */
76 h
=XTextHeight(sw
->font
)+YSPACE
;
77 frac
=min(1.0,((real
)sw
->wheight
)/((real
)sw
->nlines
));
78 btop
=((((real
)sw
->top
)/((real
)sw
->nlines
)))*(sw
->wd
.height
);
79 bheight
=frac
*sw
->wd
.height
;
84 nl
=min(sw
->nlines
,sw
->top
+sw
->wheight
);
87 XClearWindow(x11
->disp
,w
);
89 printf("btop: %d, bheight: %d, frac: %e, h: %e\n",btop
,bheight
,frac
,h
);
92 XSetForeground(x11
->disp
,x11
->gc
,LIGHTGREY
);
93 XFillRectangle(x11
->disp
,w
,x11
->gc
,2,btop
+2,barw
-4,bheight
-4);
94 XDrawLine(x11
->disp
,w
,x11
->gc
,barw
,0,barw
,sw
->wd
.height
);
97 XSetForeground(x11
->disp
,x11
->gc
,sw
->fg
);
98 for(i
=sw
->top
; (i
<nl
); i
++) {
99 SpecialTextInRect(x11
,sw
->font
,w
,
100 sw
->lines
[i
],barw
+2,y
,sw
->wd
.width
-barw
-4,(int)h
,
104 XSetForeground(x11
->disp
,x11
->gc
,x11
->fg
);
106 case ConfigureNotify
:
107 calc_scrollw(sw
,event
->xconfigure
.width
,event
->xconfigure
.height
);
110 if (event
->xbutton
.x
< barw
) {
111 int y
=event
->xbutton
.y
;
113 if (sw
->nlines
> sw
->wheight
) {
115 sw
->top
=max(0,sw
->top
-1);
116 else if (y
>btop
+bheight
)
117 sw
->top
=min(sw
->nlines
-sw
->wheight
,sw
->top
+1);
120 ExposeWin(x11
->disp
,sw
->wd
.self
);
131 t_scrollw
*init_scrollw(t_x11
*x11
,Window parent
,int x
,int y
,int w
,int h
,
132 unsigned long fg
,unsigned long bg
)
138 InitWin(&sw
->wd
,x
,y
,w
,h
,1,"Scroll Window");
142 sw
->wd
.self
=XCreateSimpleWindow(x11
->disp
,parent
,x
,y
,w
,h
,
143 sw
->wd
.bwidth
,fg
,bg
);
144 x11
->RegisterCallback(x11
,sw
->wd
.self
,parent
,SWCallback
,sw
);
145 x11
->SetInputMask(x11
,sw
->wd
.self
,ExposureMask
| ButtonPressMask
|
146 StructureNotifyMask
);
147 calc_scrollw(sw
,w
,h
);
152 void show_scrollw(t_x11
*x11
,t_scrollw
*sw
)
154 XMapWindow(x11
->disp
,sw
->wd
.self
);
157 char *tab2spc(char *buf
)
163 snew(buf2
,8*strlen(buf
)+1);
164 for(i
=j
=0; (buf
[i
]!='\0'); i
++)
168 } while ((j
% 8)!=0);
177 void read_lines(FILE *in
,t_scrollw
*sw
)
181 while (fgets2(buf
,1023,in
)) {
183 srenew(sw
->lines
,sw
->nlines
);
184 sw
->lines
[sw
->nlines
-1]=tab2spc(buf
);
189 main(int argc
, char *argv
[])
194 if ((x11
=GetX11(&argc
,argv
))==NULL
) {
195 fprintf(stderr
,"No X!\n");
198 sw
=init_scrollw(x11
,x11
->root
,0,0,600,200,WHITE
,BLACK
);
199 read_lines(stdin
,sw
);
200 show_scrollw(x11
,sw
);