Debian Codegraph @

sys/praat_logo.cpp

raw symbols SCIP
1 /* praat_logo.cpp
2 *
3 * Copyright (C) 1996-2024 Paul Boersma
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "praatP.h"
20 #include "Picture.h"
21
22 static void logo_defaultDraw (Graphics g) {
23 Graphics_setColour (g, Melder_MAGENTA);
24 Graphics_fillRectangle (g, 0.0, 1.0, 0.0, 1.0);
25 Graphics_setGrey (g, 0.5);
26 Graphics_fillRectangle (g, 0.05, 0.95, 0.1, 0.9);
27 Graphics_setTextAlignment (g, Graphics_CENTRE, Graphics_HALF);
28 Graphics_setColour (g, Melder_YELLOW);
29 Graphics_setFont (g, kGraphics_font::TIMES);
30 Graphics_setFontSize (g, 24);
31 Graphics_setFontStyle (g, Graphics_ITALIC);
32 Graphics_setUnderscoreIsSubscript (g, false); // because program names may contain underscores
33 Graphics_text (g, 0.5, 0.6, Melder_upperCaseAppName());
34 Graphics_setFontStyle (g, 0);
35 Graphics_setFontSize (g, 12);
36 Graphics_text (g, 0.5, 0.25, U"\\s{Built on the} %%Praat shell%\\s{,© Paul Boersma, 1992-2024");
37 }
38
39 static struct {
40 double width_mm, height_mm;
41 void (*draw) (Graphics g);
42 GuiDialog dia;
43 GuiForm form;
44 GuiDrawingArea drawingArea;
45 autoGraphics graphics;
46 } theLogo = { 90, 40, logo_defaultDraw };
47
48 void praat_setLogo (double width_mm, double height_mm, void (*draw) (Graphics g)) {
49 theLogo.width_mm = width_mm;
50 theLogo.height_mm = height_mm;
51 theLogo.draw = draw;
52 }
53
54 static void gui_drawingarea_cb_expose (Thing /* me */, GuiDrawingArea_ExposeEvent /* event */) {
55 theLogo.draw (theLogo.graphics.get());
56 }
57
58 static void gui_drawingarea_cb_mouse (Thing /* me */, GuiDrawingArea_MouseEvent /* event */) {
59 GuiThing_hide (theLogo.form);
60 }
61
62 static void gui_cb_goAway (Thing /* boss */) {
63 GuiThing_hide (theLogo.form);
64 }
65
66 void praat_showLogo () {
67 if (theCurrentPraatApplication -> batch || ! theLogo.draw)
68 return;
69 if (! theLogo.dia) {
70 int width = theLogo.width_mm / 25.4 * Gui_getResolution (nullptr);
71 int height = theLogo.height_mm / 25.4 * Gui_getResolution (nullptr);
72 theLogo.dia = GuiDialog_create (theCurrentPraatApplication -> topShell, 100, 100, width, height,
73 U"About", gui_cb_goAway, nullptr, GuiDialog_Modality::MODELESS);
74 theLogo.form = theLogo.dia;
75 theLogo.drawingArea = GuiDrawingArea_createShown (theLogo.form, 0, width, 0, height,
76 gui_drawingarea_cb_expose, gui_drawingarea_cb_mouse, nullptr, nullptr, nullptr, nullptr, 0);
77 /*
78 Note about ordering the following three statements (2021-01-20).
79 On some platforms (e.g. on macOS 10.10, but not 10.15), showing entails immediate drawing.
80 So the Graphics has to exist before that.
81 (It is possible that the *native* graphics *context* is created later.)
82 */
83 theLogo.graphics = Graphics_create_xmdrawingarea (theLogo.drawingArea);
84 GuiThing_show (theLogo.form);
85 GuiThing_show (theLogo.dia);
86 } else {
87 GuiThing_show (theLogo.form);
88 GuiThing_show (theLogo.dia);
89 }
90 }
91
92 /* End of file praat_logo.cpp */