Tagged files with gromacs 3.0 header and added some license info
[alexxy/gromacs.git] / src / ngmx / logo.c
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 3.0
11  * 
12  * Copyright (c) 1991-2001
13  * BIOSON Research Institute, Dept. of Biophysical Chemistry
14  * University of Groningen, The Netherlands
15  * 
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  * 
21  * If you want to redistribute modifications, please consider that
22  * scientific software is very special. Version control is crucial -
23  * bugs must be traceable. We will be happy to consider code for
24  * inclusion in the official distribution, but derived work must not
25  * be called official GROMACS. Details are found in the README & COPYING
26  * files - if they are missing, get the official version at www.gromacs.org.
27  * 
28  * To help us fund GROMACS development, we humbly ask that you cite
29  * the papers on the package - you can find them in the top README file.
30  * 
31  * Do check out http://www.gromacs.org , or mail us at gromacs@gromacs.org .
32  * 
33  * And Hey:
34  * Good gRace! Old Maple Actually Chews Slate
35  */
36 static char *SRCID_logo_c = "$Id$";
37 #include "sysstuff.h"
38 #include "Xstuff.h"
39 #include "xutil.h"
40 #include "smalloc.h"
41 #include "macros.h"
42 #include "copyrite.h"
43 #include "logo.h"
44
45 typedef struct {
46   int   x,y,rad;
47   unsigned long *col;
48 } t_circle;
49
50 typedef struct {
51   char        *text;
52   int         y,h;
53   XFontStruct *fnt;
54 } t_mess;
55
56 void show_logo(t_x11 *x11,t_logo *logo)
57 {
58   XMapWindow(x11->disp,logo->wd.self);
59   XMapSubwindows(x11->disp,logo->wd.self);
60 }
61
62 void hide_logo(t_x11 *x11,t_logo *logo)
63 {
64   XUnmapWindow(x11->disp,logo->wd.self);
65 }
66
67 static bool LogoCallBack(t_x11 *x11,XEvent *event, Window w, void *data)
68 {
69   /* Assume window is 100x110 */
70   static bool bFirst=TRUE;
71 #define CSIZE 9
72 #define NSIZE 8
73 #define OSIZE 9
74 #define HSIZE 7
75 #define YOFFS 30
76   static t_circle c[] = {
77     { 10,YOFFS+12,CSIZE,&LIGHTGREEN },
78     { 20,YOFFS+22,CSIZE,&LIGHTGREEN },
79     { 20,YOFFS+34,OSIZE,&LIGHTRED   },
80     { 30,YOFFS+12,NSIZE,&LIGHTCYAN  },
81     { 30,YOFFS+ 2,HSIZE ,&WHITE     },
82     { 40,YOFFS+22,CSIZE,&LIGHTGREEN },
83     { 40,YOFFS+34,CSIZE,&LIGHTGREEN },
84     { 50,YOFFS+12,CSIZE,&LIGHTGREEN },
85     { 50,YOFFS   ,OSIZE,&LIGHTRED   },
86     { 60,YOFFS+22,NSIZE,&LIGHTCYAN  },
87     { 60,YOFFS+32,HSIZE, &WHITE     },
88     { 70,YOFFS+12,CSIZE,&LIGHTGREEN },
89     { 80,YOFFS+22,CSIZE,&LIGHTGREEN },
90     { 80,YOFFS+34,OSIZE,&LIGHTRED   },
91     { 90,YOFFS+12,NSIZE,&LIGHTCYAN  },
92     { 90,YOFFS+ 2,HSIZE,&WHITE      },
93     {100,YOFFS+22,CSIZE,&LIGHTGREEN }
94   };
95   static int lines[] = {
96     0,1, 1,2, 1,3, 3,4, 3,5, 5,6, 5,7, 7,8, 7,9, 
97     9,10, 9,11, 11,12, 12,13, 12,14, 14,15, 14,16
98   };
99 #define COFFS 70
100   static t_mess Mess[] = {
101     { "GROMACS",                         0,       20, NULL },
102     { NULL,                             16,        9, NULL },
103     { "Copyright (c) 1991-1998",        COFFS+ 2,  9, NULL },
104     { "Dept. of Biophysical Chemistry", COFFS+11,  9, NULL },
105     { "University of Groningen",        COFFS+20,  9, NULL },
106     { "click to dismiss",               COFFS+31,  8, NULL }
107     };
108 #define NMESS asize(Mess)
109   int       i;
110   real      wfac,hfac;
111   t_logo    *logo;
112   t_windata *wd;
113
114   logo=(t_logo *)data;
115   wd=&(logo->wd);
116   if (bFirst) {
117     wfac=wd->width/110.0;
118     hfac=wd->height/110.0;
119     for(i=0; (i<asize(c)); i++) {
120       c[i].x *= wfac;
121       c[i].y *= hfac;
122     }
123     Mess[1].text=GromacsVersion();
124     for(i=0; (i<NMESS); i++) {
125       Mess[i].y *= hfac;
126       Mess[i].h *= hfac;
127       Mess[i].fnt = (i==0) ? logo->bigfont : (i==NMESS-1) ? x11->font :
128         logo->smallfont;
129     }
130     bFirst=FALSE;
131   }
132   switch (event->type) {
133   case Expose:
134     XSetForeground(x11->disp,x11->gc,WHITE);
135     XSetLineAttributes(x11->disp,x11->gc,3,LineSolid,CapNotLast,JoinRound);
136     for(i=0; (i<asize(lines)); i+=2) {
137       XDrawLine(x11->disp,wd->self,x11->gc,
138                 c[lines[i]].x,c[lines[i]].y,c[lines[i+1]].x,c[lines[i+1]].y);
139     }
140     XSetLineAttributes(x11->disp,x11->gc,1,LineSolid,CapNotLast,JoinRound);
141     for(i=0; (i<asize(c)); i++) {
142       XSetForeground(x11->disp,x11->gc,*(c[i].col));
143       XFillCircle(x11->disp,wd->self,x11->gc,c[i].x,c[i].y,c[i].rad);
144     }
145     XSetForeground(x11->disp,x11->gc,BLACK);
146     XDrawRectangle(x11->disp,wd->self,x11->gc,2,2,wd->width-5,wd->height-5);
147     for(i=0; (i<asize(Mess)); i++)
148       SpecialTextInRect(x11,Mess[i].fnt,wd->self,Mess[i].text,
149                         0,Mess[i].y,wd->width,Mess[i].h,
150                         eXCenter,eYCenter);
151     XSetForeground(x11->disp,x11->gc,x11->fg);
152     break;
153   case ButtonPress:
154     hide_logo(x11,logo);
155     break;
156   default:
157     break;
158   }
159
160   return FALSE;
161 }
162
163 t_logo *init_logo(t_x11 *x11,Window parent)
164 {
165   static char *bfname[]= {
166     "-b&h-lucida-bold-i-normal-sans-34-240-100-100-p-215-iso8859-1",
167     "-b&h-lucida-bold-i-normal-sans-26-190-100-100-p-166-iso8859-1",
168     "lucidasans-bolditalic-24",
169     "lucidasans-italic-24",
170     "10x20",
171     "fixed"
172     };
173 #define NBF asize(bfname)
174   static char *sfname[]= {
175     "lucidasans-bold-18",
176     "10x20",
177     "fixed"
178     };
179 #define NSF asize(sfname)
180   int    i;
181   unsigned long  bg;
182   char   *newcol;
183   t_logo *logo;
184
185   snew(logo,1);
186   InitWin(&logo->wd,0,0,360,270,1,"GROMACS");
187   bg=LIGHTGREY;
188   if ((newcol=getenv("LOGO"))!=NULL)
189     GetNamedColor(x11,newcol,&bg);
190   logo->wd.self=XCreateSimpleWindow(x11->disp,parent,
191                                     logo->wd.x, logo->wd.y, 
192                                     logo->wd.width,logo->wd.height,
193                                     logo->wd.bwidth,WHITE,bg);
194   for (i=0,logo->bigfont=NULL; (i<NBF); i++)
195     if ((logo->bigfont=XLoadQueryFont(x11->disp,bfname[i]))!=NULL)
196       break;
197   if (i==NBF) {
198     perror(bfname[i-1]);
199     exit(1);
200   }
201 #ifdef DEBUG
202   fprintf(stderr,"Big Logofont: %s\n",bfname[i]);
203 #endif
204   for (i=0,logo->smallfont=NULL; (i<NSF); i++)
205     if ((logo->smallfont=XLoadQueryFont(x11->disp,sfname[i]))!=NULL)
206       break;
207   if (i==NSF) {
208     perror(sfname[i-1]);
209     exit(1);
210   }
211 #ifdef DEBUG
212   fprintf(stderr,"Small Logofont: %s\n",sfname[i]);
213 #endif
214   x11->RegisterCallback(x11,logo->wd.self,parent,LogoCallBack,logo);
215   x11->SetInputMask(x11,logo->wd.self,ButtonPressMask | ExposureMask);
216
217   return logo;
218 }
219
220 void done_logo(t_x11 *x11,t_logo *logo)
221 {
222   x11->UnRegisterCallback(x11,logo->wd.self);
223 }