Update copyright statements and change license to LGPL
[alexxy/gromacs.git] / src / ngmx / logo.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
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, 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.
11  *
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.
16  *
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.
21  *
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.
26  *
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.
34  *
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.
37  */
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #include "sysstuff.h"
43 #include "xutil.h"
44 #include "Xstuff.h"
45 #include "smalloc.h"
46 #include "macros.h"
47 #include "copyrite.h"
48 #include "logo.h"
49
50 typedef struct {
51   int   x,y,rad;
52   unsigned long *col;
53 } t_circle;
54
55 typedef struct {
56   const char  *text;
57   int         y,h;
58   XFontStruct *fnt;
59 } t_mess;
60
61 void show_logo(t_x11 *x11,t_logo *logo)
62 {
63   XMapWindow(x11->disp,logo->wd.self);
64   XMapSubwindows(x11->disp,logo->wd.self);
65 }
66
67 void hide_logo(t_x11 *x11,t_logo *logo)
68 {
69   XUnmapWindow(x11->disp,logo->wd.self);
70 }
71
72 static gmx_bool LogoCallBack(t_x11 *x11,XEvent *event, Window w, void *data)
73 {
74   /* Assume window is 100x110 */
75   static gmx_bool bFirst=TRUE;
76 #define CSIZE 9
77 #define NSIZE 8
78 #define OSIZE 9
79 #define HSIZE 7
80 #define YOFFS 30
81   static t_circle c[] = {
82     { 10,YOFFS+12,CSIZE,&LIGHTGREEN },
83     { 20,YOFFS+22,CSIZE,&LIGHTGREEN },
84     { 20,YOFFS+34,OSIZE,&LIGHTRED   },
85     { 30,YOFFS+12,NSIZE,&LIGHTCYAN  },
86     { 30,YOFFS+ 2,HSIZE ,&WHITE     },
87     { 40,YOFFS+22,CSIZE,&LIGHTGREEN },
88     { 40,YOFFS+34,CSIZE,&LIGHTGREEN },
89     { 50,YOFFS+12,CSIZE,&LIGHTGREEN },
90     { 50,YOFFS   ,OSIZE,&LIGHTRED   },
91     { 60,YOFFS+22,NSIZE,&LIGHTCYAN  },
92     { 60,YOFFS+32,HSIZE, &WHITE     },
93     { 70,YOFFS+12,CSIZE,&LIGHTGREEN },
94     { 80,YOFFS+22,CSIZE,&LIGHTGREEN },
95     { 80,YOFFS+34,OSIZE,&LIGHTRED   },
96     { 90,YOFFS+12,NSIZE,&LIGHTCYAN  },
97     { 90,YOFFS+ 2,HSIZE,&WHITE      },
98     {100,YOFFS+22,CSIZE,&LIGHTGREEN }
99   };
100   static int lines[] = {
101     0,1, 1,2, 1,3, 3,4, 3,5, 5,6, 5,7, 7,8, 7,9, 
102     9,10, 9,11, 11,12, 12,13, 12,14, 14,15, 14,16
103   };
104 #define COFFS 70
105   static t_mess Mess[] = {
106     { "GROMACS",                         0,       20, NULL },
107     { NULL,                             16,        9, NULL },
108     { "Copyright (c) 1991-2010",        COFFS+ 2,  9, NULL },
109     { "D.v.d.Spoel, E.Lindahl, B.Hess", COFFS+11,  9, NULL },
110     { "& Groningen University ",        COFFS+20,  9, NULL },
111     { "click to dismiss",               COFFS+31,  8, NULL }
112     };
113 #define NMESS asize(Mess)
114   int       i;
115   real      wfac,hfac;
116   t_logo    *logo;
117   t_windata *wd;
118
119   logo=(t_logo *)data;
120   wd=&(logo->wd);
121   if (bFirst) {
122     wfac=wd->width/110.0;
123     hfac=wd->height/110.0;
124     for(i=0; (i<asize(c)); i++) {
125       c[i].x *= wfac;
126       c[i].y *= hfac;
127     }
128     Mess[1].text=GromacsVersion();
129     for(i=0; (i<NMESS); i++) {
130       Mess[i].y *= hfac;
131       Mess[i].h *= hfac;
132       Mess[i].fnt = (i==0) ? logo->bigfont : (i==NMESS-1) ? x11->font :
133         logo->smallfont;
134     }
135     bFirst=FALSE;
136   }
137   switch (event->type) {
138   case Expose:
139     XSetForeground(x11->disp,x11->gc,WHITE);
140     XSetLineAttributes(x11->disp,x11->gc,3,LineSolid,CapNotLast,JoinRound);
141     for(i=0; (i<asize(lines)); i+=2) {
142       XDrawLine(x11->disp,wd->self,x11->gc,
143                 c[lines[i]].x,c[lines[i]].y,c[lines[i+1]].x,c[lines[i+1]].y);
144     }
145     XSetLineAttributes(x11->disp,x11->gc,1,LineSolid,CapNotLast,JoinRound);
146     for(i=0; (i<asize(c)); i++) {
147       XSetForeground(x11->disp,x11->gc,*(c[i].col));
148       XFillCircle(x11->disp,wd->self,x11->gc,c[i].x,c[i].y,c[i].rad);
149     }
150     XSetForeground(x11->disp,x11->gc,BLACK);
151     XDrawRectangle(x11->disp,wd->self,x11->gc,2,2,wd->width-5,wd->height-5);
152     for(i=0; (i<asize(Mess)); i++)
153       SpecialTextInRect(x11,Mess[i].fnt,wd->self,Mess[i].text,
154                         0,Mess[i].y,wd->width,Mess[i].h,
155                         eXCenter,eYCenter);
156     XSetForeground(x11->disp,x11->gc,x11->fg);
157     break;
158   case ButtonPress:
159     hide_logo(x11,logo);
160     return logo->bQuitOnClick;
161     break;
162   default:
163     break;
164   }
165
166   return FALSE;
167 }
168
169 t_logo *init_logo(t_x11 *x11,Window parent,gmx_bool bQuitOnClick)
170 {
171   static const char *bfname[]= {
172     "-b&h-lucida-bold-i-normal-sans-34-240-100-100-p-215-iso8859-1",
173     "-b&h-lucida-bold-i-normal-sans-26-190-100-100-p-166-iso8859-1",
174     "lucidasans-bolditalic-24",
175     "lucidasans-italic-24",
176     "10x20",
177     "fixed"
178     };
179 #define NBF asize(bfname)
180   static const char *sfname[]= {
181     "lucidasans-bold-18",
182     "10x20",
183     "fixed"
184     };
185 #define NSF asize(sfname)
186   int    i;
187   unsigned long  bg;
188   char   *newcol;
189   t_logo *logo;
190
191   snew(logo,1);
192   logo->bQuitOnClick = bQuitOnClick;
193   InitWin(&logo->wd,0,0,360,270,1,"GROMACS");
194   bg=LIGHTGREY;
195   if ((newcol=getenv("LOGO"))!=NULL)
196     GetNamedColor(x11,newcol,&bg);
197   logo->wd.self=XCreateSimpleWindow(x11->disp,parent,
198                                     logo->wd.x, logo->wd.y, 
199                                     logo->wd.width,logo->wd.height,
200                                     logo->wd.bwidth,WHITE,bg);
201   for (i=0,logo->bigfont=NULL; (i<NBF); i++)
202     if ((logo->bigfont=XLoadQueryFont(x11->disp,bfname[i]))!=NULL)
203       break;
204   if (i==NBF) {
205     perror(bfname[i-1]);
206     exit(1);
207   }
208 #ifdef DEBUG
209   fprintf(stderr,"Big Logofont: %s\n",bfname[i]);
210 #endif
211   for (i=0,logo->smallfont=NULL; (i<NSF); i++)
212     if ((logo->smallfont=XLoadQueryFont(x11->disp,sfname[i]))!=NULL)
213       break;
214   if (i==NSF) {
215     perror(sfname[i-1]);
216     exit(1);
217   }
218 #ifdef DEBUG
219   fprintf(stderr,"Small Logofont: %s\n",sfname[i]);
220 #endif
221   x11->RegisterCallback(x11,logo->wd.self,parent,LogoCallBack,logo);
222   x11->SetInputMask(x11,logo->wd.self,ButtonPressMask | ExposureMask);
223
224   return logo;
225 }
226
227 void done_logo(t_x11 *x11,t_logo *logo)
228 {
229   x11->UnRegisterCallback(x11,logo->wd.self);
230 }