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