On this page:

32 Splash🔗

 (require framework/splash) package: gui-lib

This module helps support applications with splash screens like the one in DrRacket.

When this module is invoked, it sets the current-load parameter to a procedure that counts how many files are loaded (until shutdown-splash is called) and uses that number to control the gauge along the bottom of the splash screen.


(start-splash draw-spec    
  [#:allow-funny? allow-funny?    
  #:frame-icon frame-icon])  void?
  draw-spec : 
(or/c path-string?
      (is-a?/c bitmap%)
      (vector/c (or/c (-> (is-a?/c dc<%>) void?)
                      (-> (is-a?/c dc<%>)
  splash-title : string?
  width-default : exact-nonnegative-integer?
  allow-funny? : boolean? = #f
  frame-icon : 
(or/c #f
      (is-a?/c bitmap%)
      (cons/c (is-a?/c bitmap%)
              (is-a?/c bitmap%)))
 = #f
Starts a new splash screen. The splash screen is created in its own, new eventspace. The progress gauge at the bottom of the window advances as files are loaded (monitored via the current-load parameter).

The draw-spec determines what the splash window contains. The splash-title is used as the title of the window and the width-default determines how many progress steps the gauge in the splash screen should contain if there is no preference saved for the splash screen width. The splash library uses get-preference and put-preferences to store preferences, using

(string->symbol (format "plt:~a-splash-max-width" splash-title))

as the key for the preference. Each time the app starts up, the maximum width is reset based on the number of files that were loaded that time.

If the draw-spec is a path-string?, then the path is expected to be a file that contains a bitmap that is drawn as the contents of the splash screen. If it is a bitmap, then that bitmap is used directly. If draw-spec is a vector, then the vector’s first element is a procedure that is called to draw the splash screen and the other two integers are the size of the splash screen, width followed by height. If the procedure accepts only one argument, then it is called with a dc<%> object where the drawing should occur. If it accepts 5 arguments, it is called with the dc<%>, as well as (in order) the current value of the gauge, the maximum value of the gauge, and the width and the height of the area to draw.

The allow-funny? argument determines if a special gauge is used on Christmas day.

The frame-icon is used just like the value of the parameter frame:current-icon is used, but for the splash screen.


(shutdown-splash)  void?

Stops the splash window’s gauge from advancing. Call this after all of the files have been loaded.


(close-splash)  void?

Closes the splash window. Call shutdown-splash first. You can leave some time between these two if there is more initialization work to be done where you do not want to count loaded files.


(add-splash-icon bmp x y)  void?

  bmp : (is-a?/c bitmap%)
  x : real?
  y : real?
Adds an icon to the splash screen. (DrRacket uses this function to show the tools as they are loaded.)


(get-splash-bitmap)  (or/c #f (is-a?/c bitmap%))

Returns the splash bitmap unless one has not been set.


(set-splash-bitmap bmp)  void?

  bmp : (is-a?/c bitmap%)
Sets the splash bitmap to bmp and triggers a redrawing of the splash screen. Don’t use this to set the initial bitmap, use start-splash instead.


(get-splash-canvas)  (is-a?/c canvas%)

Returns the canvas where the splash screen bitmap is drawn (if there is a bitmap); see start-splash for how the splash is drawn.
Returns the splash screen’s eventspace.
Returns the callback that is invoked when redrawing the splash screen.
Sets the callback that is invoked when redrawing the splash screen. See start-splash for what the arguments are.


(set-splash-progress-bar?! b)  void?

  b : boolean?
Calling this procedure with #f removes the progress bar from the splash screen. Useful in conjunction with setting your own paint callback for the splash screen that measures progress in its own way, during drawing. DrRacket uses this on King Kamehameha and Prince Kuhio day.


(set-splash-char-observer obs)  void?

  obs : (-> (is-a?/c key-event%) any)
Sets a procedure that is called whenever a user types a key with the splash screen as the focus.


(set-splash-event-callback obj)  void?

  obj : (-> (is-?/c mouse-event%) any)
Sets a procedure that is called whenever a mouse event happens in the splash canvas.


(get-splash-event-callback)  (-> (is-?/c mouse-event%) any)

Returns the last procedure passed to set-splash-event-callback or void, if set-splash-event-callback has not been called.
Sets a procedure that is called each time the splash gauge changes. If the procedure returns a true value (i.e., not #f), then the splash screen is redrawn. The procedure is called with the current value of the gauge and the maximum value.

The default function is (lambda (curr tot) #f).
Returns the width of the splash drawing area / bitmap. See start-splash for the details of the size and how things are drawn.
Returns the width of the splash drawing area / bitmap. See start-splash for the details of the size and how things are drawn.


(refresh-splash)  void?

Triggers a refresh of the splash, handling the details of double buffering and doing the drawing on the splash’s eventspace’s main thread.