89424d59d66ab2064d6cd2c11dd6a39a59bdd767
[alexxy/gromacs.git] / src / programs / view / logo.cpp
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-2013, The GROMACS development team.
6  * Copyright (c) 2013,2014, by the GROMACS development team, led by
7  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8  * and including many others, as listed in the AUTHORS file in the
9  * top-level source directory and at http://www.gromacs.org.
10  *
11  * GROMACS is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public License
13  * as published by the Free Software Foundation; either version 2.1
14  * of the License, or (at your option) any later version.
15  *
16  * GROMACS is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with GROMACS; if not, see
23  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
25  *
26  * If you want to redistribute modifications to GROMACS, please
27  * consider that scientific software is very special. Version
28  * control is crucial - bugs must be traceable. We will be happy to
29  * consider code for inclusion in the official distribution, but
30  * derived work must not be called official GROMACS. Details are found
31  * in the README & COPYING files - if they are missing, get the
32  * official version at http://www.gromacs.org.
33  *
34  * To help us fund GROMACS development, we humbly ask that you cite
35  * the research papers on the package. Check out http://www.gromacs.org.
36  */
37 #include "gmxpre.h"
38
39 #include "config.h"
40
41 #include <stdlib.h>
42
43 #include "gromacs/legacyheaders/macros.h"
44 #include "xutil.h"
45 #include "Xstuff.h"
46 #include "gromacs/legacyheaders/copyrite.h"
47 #include "logo.h"
48
49 #include "gromacs/utility/real.h"
50 #include "gromacs/utility/smalloc.h"
51
52 typedef struct {
53     int            x, y, rad;
54     unsigned long *col;
55 } t_circle;
56
57 typedef struct {
58     const char  *text;
59     int          y, h;
60     XFontStruct *fnt;
61 } t_mess;
62
63 void show_logo(t_x11 *x11, t_logo *logo)
64 {
65     XMapWindow(x11->disp, logo->wd.self);
66     XMapSubwindows(x11->disp, logo->wd.self);
67 }
68
69 void hide_logo(t_x11 *x11, t_logo *logo)
70 {
71     XUnmapWindow(x11->disp, logo->wd.self);
72 }
73
74 static bool LogoCallBack(t_x11 *x11, XEvent *event, Window /*w*/, void *data)
75 {
76     /* Assume window is 100x110 */
77     static bool bFirst = true;
78 #define CSIZE 9
79 #define NSIZE 8
80 #define OSIZE 9
81 #define HSIZE 7
82 #define YOFFS 30
83     static t_circle c[] = {
84         { 10, YOFFS+12, CSIZE, &LIGHTGREEN },
85         { 20, YOFFS+22, CSIZE, &LIGHTGREEN },
86         { 20, YOFFS+34, OSIZE, &LIGHTRED   },
87         { 30, YOFFS+12, NSIZE, &LIGHTCYAN  },
88         { 30, YOFFS+ 2, HSIZE, &WHITE     },
89         { 40, YOFFS+22, CSIZE, &LIGHTGREEN },
90         { 40, YOFFS+34, CSIZE, &LIGHTGREEN },
91         { 50, YOFFS+12, CSIZE, &LIGHTGREEN },
92         { 50, YOFFS,    OSIZE, &LIGHTRED   },
93         { 60, YOFFS+22, NSIZE, &LIGHTCYAN  },
94         { 60, YOFFS+32, HSIZE, &WHITE     },
95         { 70, YOFFS+12, CSIZE, &LIGHTGREEN },
96         { 80, YOFFS+22, CSIZE, &LIGHTGREEN },
97         { 80, YOFFS+34, OSIZE, &LIGHTRED   },
98         { 90, YOFFS+12, NSIZE, &LIGHTCYAN  },
99         { 90, YOFFS+ 2, HSIZE, &WHITE      },
100         {100, YOFFS+22, CSIZE, &LIGHTGREEN }
101     };
102     static int      lines[] = {
103         0, 1, 1, 2, 1, 3, 3, 4, 3, 5, 5, 6, 5, 7, 7, 8, 7, 9,
104         9, 10, 9, 11, 11, 12, 12, 13, 12, 14, 14, 15, 14, 16
105     };
106 #define COFFS 70
107     static t_mess   Mess[] = {
108         { "GROMACS",                         0,       20, NULL },
109         { NULL,                             16,        9, NULL },
110         { "Copyright (c) 1991-2013",        COFFS+ 2,  9, NULL },
111         { "D.v.d.Spoel, E.Lindahl, B.Hess", COFFS+11,  9, NULL },
112         { "& Groningen University ",        COFFS+20,  9, NULL },
113         { "click to dismiss",               COFFS+31,  8, NULL }
114     };
115 #define NMESS asize(Mess)
116     int             i;
117     t_logo         *logo;
118     t_windata      *wd;
119
120     logo = (t_logo *)data;
121     wd   = &(logo->wd);
122     if (bFirst)
123     {
124         const real wfac = wd->width/110.0;
125         const real hfac = wd->height/110.0;
126         for (i = 0; (i < asize(c)); i++)
127         {
128             c[i].x *= wfac;
129             c[i].y *= hfac;
130         }
131         Mess[1].text = GromacsVersion();
132         for (i = 0; (i < NMESS); i++)
133         {
134             Mess[i].y  *= hfac;
135             Mess[i].h  *= hfac;
136             Mess[i].fnt = (i == 0) ? logo->bigfont : (i == NMESS-1) ? x11->font :
137                 logo->smallfont;
138         }
139         bFirst = false;
140     }
141     switch (event->type)
142     {
143         case Expose:
144             XSetForeground(x11->disp, x11->gc, WHITE);
145             XSetLineAttributes(x11->disp, x11->gc, 3, LineSolid, CapNotLast, JoinRound);
146             for (i = 0; (i < asize(lines)); i += 2)
147             {
148                 XDrawLine(x11->disp, wd->self, x11->gc,
149                           c[lines[i]].x, c[lines[i]].y, c[lines[i+1]].x, c[lines[i+1]].y);
150             }
151             XSetLineAttributes(x11->disp, x11->gc, 1, LineSolid, CapNotLast, JoinRound);
152             for (i = 0; (i < asize(c)); i++)
153             {
154                 XSetForeground(x11->disp, x11->gc, *(c[i].col));
155                 XFillCircle(x11->disp, wd->self, x11->gc, c[i].x, c[i].y, c[i].rad);
156             }
157             XSetForeground(x11->disp, x11->gc, BLACK);
158             XDrawRectangle(x11->disp, wd->self, x11->gc, 2, 2, wd->width-5, wd->height-5);
159             for (i = 0; (i < NMESS); i++)
160             {
161                 SpecialTextInRect(x11, Mess[i].fnt, wd->self, Mess[i].text,
162                                   0, Mess[i].y, wd->width, Mess[i].h,
163                                   eXCenter, eYCenter);
164             }
165             XSetForeground(x11->disp, x11->gc, x11->fg);
166             break;
167         case ButtonPress:
168             hide_logo(x11, logo);
169             return logo->bQuitOnClick;
170             break;
171         default:
172             break;
173     }
174
175     return false;
176 }
177
178 t_logo *init_logo(t_x11 *x11, Window parent, bool bQuitOnClick)
179 {
180     static const char *bfname[] = {
181         "-b&h-lucida-bold-i-normal-sans-34-240-100-100-p-215-iso8859-1",
182         "-b&h-lucida-bold-i-normal-sans-26-190-100-100-p-166-iso8859-1",
183         "lucidasans-bolditalic-24",
184         "lucidasans-italic-24",
185         "10x20",
186         "fixed"
187     };
188 #define NBF asize(bfname)
189     static const char *sfname[] = {
190         "lucidasans-bold-18",
191         "10x20",
192         "fixed"
193     };
194 #define NSF asize(sfname)
195     unsigned int       i;
196     unsigned long      bg;
197     char              *newcol;
198     t_logo            *logo;
199
200     snew(logo, 1);
201     logo->bQuitOnClick = bQuitOnClick;
202     InitWin(&logo->wd, 0, 0, 360, 270, 1, "GROMACS");
203     bg = LIGHTGREY;
204     if ((newcol = getenv("GMX_LOGO_COLOR")) != NULL)
205     {
206         GetNamedColor(x11, newcol, &bg);
207     }
208     logo->wd.self = XCreateSimpleWindow(x11->disp, parent,
209                                         logo->wd.x, logo->wd.y,
210                                         logo->wd.width, logo->wd.height,
211                                         logo->wd.bwidth, WHITE, bg);
212     for (i = 0, logo->bigfont = NULL; (i < NBF); i++)
213     {
214         if ((logo->bigfont = XLoadQueryFont(x11->disp, bfname[i])) != NULL)
215         {
216             break;
217         }
218     }
219     if (i == NBF)
220     {
221         perror(bfname[i-1]);
222         exit(1);
223     }
224 #ifdef DEBUG
225     fprintf(stderr, "Big Logofont: %s\n", bfname[i]);
226 #endif
227     for (i = 0, logo->smallfont = NULL; (i < NSF); i++)
228     {
229         if ((logo->smallfont = XLoadQueryFont(x11->disp, sfname[i])) != NULL)
230         {
231             break;
232         }
233     }
234     if (i == NSF)
235     {
236         perror(sfname[i-1]);
237         exit(1);
238     }
239 #ifdef DEBUG
240     fprintf(stderr, "Small Logofont: %s\n", sfname[i]);
241 #endif
242     x11->RegisterCallback(x11, logo->wd.self, parent, LogoCallBack, logo);
243     x11->SetInputMask(x11, logo->wd.self, ButtonPressMask | ExposureMask);
244
245     return logo;
246 }
247
248 void done_logo(t_x11 *x11, t_logo *logo)
249 {
250     x11->UnRegisterCallback(x11, logo->wd.self);
251 }