Merge "Merge branch 'release-4-6'"
[alexxy/gromacs.git] / src / programs / view / logo.cpp
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-2013, 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 "macros.h"
41 #include "xutil.h"
42 #include "Xstuff.h"
43 #include "smalloc.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 bool LogoCallBack(t_x11 *x11, XEvent *event, Window w, void *data)
70 {
71     /* Assume window is 100x110 */
72     static 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-2013",        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     {
120         wfac = wd->width/110.0;
121         hfac = wd->height/110.0;
122         for (i = 0; (i < asize(c)); i++)
123         {
124             c[i].x *= wfac;
125             c[i].y *= hfac;
126         }
127         Mess[1].text = GromacsVersion();
128         for (i = 0; (i < NMESS); i++)
129         {
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     {
139         case Expose:
140             XSetForeground(x11->disp, x11->gc, WHITE);
141             XSetLineAttributes(x11->disp, x11->gc, 3, LineSolid, CapNotLast, JoinRound);
142             for (i = 0; (i < asize(lines)); i += 2)
143             {
144                 XDrawLine(x11->disp, wd->self, x11->gc,
145                           c[lines[i]].x, c[lines[i]].y, c[lines[i+1]].x, c[lines[i+1]].y);
146             }
147             XSetLineAttributes(x11->disp, x11->gc, 1, LineSolid, CapNotLast, JoinRound);
148             for (i = 0; (i < asize(c)); i++)
149             {
150                 XSetForeground(x11->disp, x11->gc, *(c[i].col));
151                 XFillCircle(x11->disp, wd->self, x11->gc, c[i].x, c[i].y, c[i].rad);
152             }
153             XSetForeground(x11->disp, x11->gc, BLACK);
154             XDrawRectangle(x11->disp, wd->self, x11->gc, 2, 2, wd->width-5, wd->height-5);
155             for (i = 0; (i < NMESS); i++)
156             {
157                 SpecialTextInRect(x11, Mess[i].fnt, wd->self, Mess[i].text,
158                                   0, Mess[i].y, wd->width, Mess[i].h,
159                                   eXCenter, eYCenter);
160             }
161             XSetForeground(x11->disp, x11->gc, x11->fg);
162             break;
163         case ButtonPress:
164             hide_logo(x11, logo);
165             return logo->bQuitOnClick;
166             break;
167         default:
168             break;
169     }
170
171     return false;
172 }
173
174 t_logo *init_logo(t_x11 *x11, Window parent, bool bQuitOnClick)
175 {
176     static const char *bfname[] = {
177         "-b&h-lucida-bold-i-normal-sans-34-240-100-100-p-215-iso8859-1",
178         "-b&h-lucida-bold-i-normal-sans-26-190-100-100-p-166-iso8859-1",
179         "lucidasans-bolditalic-24",
180         "lucidasans-italic-24",
181         "10x20",
182         "fixed"
183     };
184 #define NBF asize(bfname)
185     static const char *sfname[] = {
186         "lucidasans-bold-18",
187         "10x20",
188         "fixed"
189     };
190 #define NSF asize(sfname)
191     unsigned int       i;
192     unsigned long      bg;
193     char              *newcol;
194     t_logo            *logo;
195
196     snew(logo, 1);
197     logo->bQuitOnClick = bQuitOnClick;
198     InitWin(&logo->wd, 0, 0, 360, 270, 1, "GROMACS");
199     bg = LIGHTGREY;
200     if ((newcol = getenv("LOGO")) != NULL)
201     {
202         GetNamedColor(x11, newcol, &bg);
203     }
204     logo->wd.self = XCreateSimpleWindow(x11->disp, parent,
205                                         logo->wd.x, logo->wd.y,
206                                         logo->wd.width, logo->wd.height,
207                                         logo->wd.bwidth, WHITE, bg);
208     for (i = 0, logo->bigfont = NULL; (i < NBF); i++)
209     {
210         if ((logo->bigfont = XLoadQueryFont(x11->disp, bfname[i])) != NULL)
211         {
212             break;
213         }
214     }
215     if (i == NBF)
216     {
217         perror(bfname[i-1]);
218         exit(1);
219     }
220 #ifdef DEBUG
221     fprintf(stderr, "Big Logofont: %s\n", bfname[i]);
222 #endif
223     for (i = 0, logo->smallfont = NULL; (i < NSF); i++)
224     {
225         if ((logo->smallfont = XLoadQueryFont(x11->disp, sfname[i])) != NULL)
226         {
227             break;
228         }
229     }
230     if (i == NSF)
231     {
232         perror(sfname[i-1]);
233         exit(1);
234     }
235 #ifdef DEBUG
236     fprintf(stderr, "Small Logofont: %s\n", sfname[i]);
237 #endif
238     x11->RegisterCallback(x11, logo->wd.self, parent, LogoCallBack, logo);
239     x11->SetInputMask(x11, logo->wd.self, ButtonPressMask | ExposureMask);
240
241     return logo;
242 }
243
244 void done_logo(t_x11 *x11, t_logo *logo)
245 {
246     x11->UnRegisterCallback(x11, logo->wd.self);
247 }