praat_logo.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* praat_logo.cpp
  2. *
  3. * Copyright (C) 1996-2012,2013,2014,2015,2016,2017 Paul Boersma, 2008 Stefan de Konink
  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. #include "praatP.h"
  19. #include "Picture.h"
  20. #include "praat_version.h"
  21. static void logo_defaultDraw (Graphics g) {
  22. Graphics_setColour (g, Graphics_MAGENTA);
  23. Graphics_fillRectangle (g, 0, 1, 0, 1);
  24. Graphics_setGrey (g, 0.5);
  25. Graphics_fillRectangle (g, 0.05, 0.95, 0.1, 0.9);
  26. Graphics_setTextAlignment (g, Graphics_CENTRE, Graphics_HALF);
  27. Graphics_setColour (g, Graphics_YELLOW);
  28. Graphics_setFont (g, kGraphics_font::TIMES);
  29. Graphics_setFontSize (g, 24);
  30. Graphics_setFontStyle (g, Graphics_ITALIC);
  31. Graphics_setUnderscoreIsSubscript (g, false); // because program names may contain underscores
  32. Graphics_text (g, 0.5, 0.6, praatP.title.get());
  33. Graphics_setFontStyle (g, 0);
  34. Graphics_setFontSize (g, 12);
  35. Graphics_text (g, 0.5, 0.25, U"\\s{Built on the} %%Praat shell%\\s{,© Paul Boersma, 1992-2017");
  36. }
  37. static struct {
  38. double width_mm, height_mm;
  39. void (*draw) (Graphics g);
  40. GuiDialog dia;
  41. GuiForm form;
  42. GuiDrawingArea drawingArea;
  43. autoGraphics graphics;
  44. } theLogo = { 90, 40, logo_defaultDraw };
  45. #if motif
  46. static void logo_timeOut (XtPointer closure, XtIntervalId *id) {
  47. (void) closure;
  48. (void) id;
  49. GuiThing_hide (theLogo.form);
  50. }
  51. #endif
  52. void praat_setLogo (double width_mm, double height_mm, void (*draw) (Graphics g)) {
  53. theLogo.width_mm = width_mm;
  54. theLogo.height_mm = height_mm;
  55. theLogo.draw = draw;
  56. }
  57. static void gui_drawingarea_cb_expose (Thing /* me */, GuiDrawingArea_ExposeEvent event) {
  58. if (! theLogo.graphics)
  59. theLogo.graphics = Graphics_create_xmdrawingarea (theLogo.drawingArea);
  60. #if gtk
  61. #if ALLOW_GDK_DRAWING
  62. Graphics_x_setCR (theLogo.graphics.get(), gdk_cairo_create (GDK_DRAWABLE (GTK_WIDGET (event -> widget -> d_widget) -> window)));
  63. #else
  64. Graphics_x_setCR (theLogo.graphics.get(), gdk_cairo_create (gtk_widget_get_window (GTK_WIDGET (event -> widget -> d_widget))));
  65. #endif
  66. cairo_rectangle ((cairo_t *) Graphics_x_getCR (theLogo.graphics.get()), (double) event->x, (double) event->y, (double) event->width, (double) event->height);
  67. cairo_clip ((cairo_t *) Graphics_x_getCR (theLogo.graphics.get()));
  68. theLogo.draw (theLogo.graphics.get());
  69. cairo_destroy ((cairo_t *) Graphics_x_getCR (theLogo.graphics.get()));
  70. #elif motif || cocoa
  71. (void) event;
  72. if (! theLogo.graphics)
  73. theLogo.graphics = Graphics_create_xmdrawingarea (theLogo.drawingArea);
  74. theLogo.draw (theLogo.graphics.get());
  75. #endif
  76. }
  77. static void gui_drawingarea_cb_click (Thing /* me */, GuiDrawingArea_ClickEvent /* event */) {
  78. GuiThing_hide (theLogo.form);
  79. }
  80. static void gui_cb_goAway (Thing /* boss */) {
  81. GuiThing_hide (theLogo.form);
  82. }
  83. void praat_showLogo (bool autoPopDown) {
  84. #if gtk
  85. static const gchar *authors [3] = { "Paul Boersma", "David Weenink", nullptr };
  86. GuiObject dialog = gtk_about_dialog_new ();
  87. #define xstr(s) str(s)
  88. #define str(s) #s
  89. gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (dialog), xstr (PRAAT_VERSION_STR));
  90. gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG (dialog), "Copyright © 1992–" xstr(PRAAT_YEAR) " by Paul Boersma and David Weenink");
  91. gtk_about_dialog_set_license (GTK_ABOUT_DIALOG (dialog), "GPL");
  92. gtk_about_dialog_set_website (GTK_ABOUT_DIALOG (dialog), "http://www.praat.org");
  93. //gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG (dialog), authors);
  94. g_signal_connect (GTK_DIALOG (dialog), "response", G_CALLBACK (gtk_widget_destroy), nullptr);
  95. gtk_dialog_run (GTK_DIALOG (dialog));
  96. #elif motif || cocoa
  97. if (theCurrentPraatApplication -> batch || ! theLogo.draw) return;
  98. if (! theLogo.dia) {
  99. int width = theLogo.width_mm / 25.4 * Gui_getResolution (nullptr);
  100. int height = theLogo.height_mm / 25.4 * Gui_getResolution (nullptr);
  101. theLogo.dia = GuiDialog_create (theCurrentPraatApplication -> topShell, 100, 100, width, height,
  102. U"About", gui_cb_goAway, nullptr, 0);
  103. theLogo.form = theLogo.dia;
  104. theLogo.drawingArea = GuiDrawingArea_createShown (theLogo.form, 0, width, 0, height,
  105. gui_drawingarea_cb_expose, gui_drawingarea_cb_click, nullptr, nullptr, nullptr, 0);
  106. }
  107. GuiThing_show (theLogo.form);
  108. GuiThing_show (theLogo.dia);
  109. #if motif
  110. if (autoPopDown)
  111. GuiAddTimeOut (2000, logo_timeOut, (XtPointer) nullptr);
  112. #endif
  113. #endif
  114. }
  115. /* End of file praat_logo.cpp */