SuperCollider CLASSES
GUI>Kits

# GUI

Factory abstraction for all GUI related core classes
Source: /Applications/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/GUI/backwardsCompatibility/GUI.sc
Inherits from: Object
See also: List of GUI classes, Introduction to GUI, ViewRedirect

## Description

SuperCollider currently supports three operating system platforms: Macintosh OSX, UNIX (Linux and FreeBSD) and Windows (with some limitations).

WARNING: The redirect system has been deprecated, please use the view classes directly.

Graphical User Interface (GUI) code, for the most part, does not need to worry about which platform is executing the code because of the view redirect system. At any time, one and only one GUI kit is active. This determines which GUI classes will be used for rendering. These classes, the active views, have prefixes for the GUI kit that created the view object: SCWindow vs. JSCWindow vs. QWindow.

GUI kit | Code to activate | Supported platform(s) | Framework | Prefix
Cocoa | `GUI.cocoa` | Mac OSX only | Cocoa | SC-
SwingOSC | `GUI.swing` | All | Java + Swing | JSC-
Qt | `GUI.qt` | All | Qt | Q-

In general, users should not concern themselves with the prefixes. Instead, work with the redirect classes, which have no prefix: Window, Button, Slider, etc. The redirect class will ask the currently-selected kit which implementation class should be used.

The GUI kit (CocoaGUI, QtGUI, SwingGUI) maps the generic view names to the implementing classes: `Window --> SCWindow, QWindow or JSCWindow`. These schemes are in turn used by ViewRedirect to provide a simple cross-platform gui syntax. The GUI class provides utilities for switching kits and other cross platform tasks.

You can get your available schemes (depending on what you installed) with:

    GUI.schemes;

For a complete list of gui classes and redirects, see List of GUI classes.

### Switching and Referring to GUI Kits

As of this writing, three GUI kits are available through the GUI class: QtGUI (Qt framework), CocoaGUI (Mac OS X native) and SwingGUI (Java). Note that SwingOSC is not part of every SuperCollider distribution, so you may have to install it separately.

You can switch the GUI kit by calling one of the following class methods:

    GUI.qt;        // use Qt in subsequent GUI creation procedures
    GUI.cocoa;    // use cocoa in subsequent GUI creation procedures
    GUI.swing;    // use swing in subsequent GUI creation procedures
            // NOTE: If you do not have SwingOSC installed, you get
            // a warning only, and do not switch; so you cannot
            // accidentally disable your gui system.

These methods return the new GUI kit implementation. The current implementation can be queried by calling

    GUI.current;    // returns the current GUI kit implementation

If you want to make a GUI kit specific switch (e.g. in a class), then you should use the following instead, as on non-OSX systems the class CocoaGUI is not in the class library path, and you cannot check for an undefined class:

    GUI.id;    // returns the current GUI kit implementation id; this is currently either \cocoa or \swing

For persistency, you can store the identifier of the kit implementation and recall the kit through the class method `fromID`:

    x = GUI.cocoa;
    y = x.id;        // store the identifier of a kit implementation
    y.postln;        // the id could be stored in a preferences file for example
    GUI.swing;
    // now switch back to the kit implementation with identifier y
    GUI.fromID( y );
    GUI.current.id.postln;    // --> cocoa

The `*use` and `*useID` methods allow you to temporarily switch the kit, so as to use it only for a dedicated block of statements:

    GUI.cocoa;
    GUI.useID(\swing, { Array.rand( 1000, 0.0, 1.0 ).plot });
    GUI.current.id.postln;    // --> still cocoa

You can get a particular kit using the `*get` method. You can switch to a particular kit using the `*set` method:

    x = GUI.get( \swing );    // note: unlike *swing and *cocoa, this does not _switch_ the current kit!
    GUI.current.id.postln;    // --> still cocoa
    GUI.set( x );            // now we make SwingOSC the current kit
    GUI.window.viewPalette;

### Extending GUI Kits

GUI Kits can be extended with custom classes by using their respective `put` methods:

    GUI.get( \cocoa ).put( \myText, SCStaticText );
    GUI.get( \swing ).put( \myText, JSCStaticText );

    GUI.cocoa;
    GUI.swing;
    (
        w = GUI.window.new;
        GUI.myText.new( w, w.view.bounds.insetBy( 20, 20 )).string_( "schoko" ).background_( Color.red );
        w.front;
    )

If you intend to add extensions from within your own classes upon class library initialization time, the preferred way is to do this in the startup process:

    MyGUIExtension {
        *initClass {
            StartUp.add({
                var scheme;

                scheme = GUI.get( \cocoa );
                if( scheme.notNil, {scheme.put( \myText, SCStaticText )});
                scheme = GUI.get( \swing );
                if( scheme.notNil, {scheme.put( \myText, JSCStaticText )});
            });
        }
    }

## Class Methods

### Methods and Variables for GUI

### *new (key)

### *makeGUI (key, args, properties)

### *initClass

Sets the `skin` to default values on compile.

    fontSpecs: ["Helvetica", 10],
    fontColor: Color.black,
    background: Color(0.8, 0.85, 0.7, 0.5),
    foreground: Color.grey(0.95),
    onColor: Color(0.5, 1, 0.5),
    offColor: Color.clear,
    gap: 0@0,
    margin: 2@2,
    buttonHeight: 16

### *cocoa: METHOD NOT FOUND!

Makes Cocoa (Mac OS X GUI) the current scheme and returns it. Subsequent GUI object calls to GUI are delegated to cocoa. Returns the current (cocoa) scheme.

### *swing

Makes Swing (Java GUI) the current scheme and returns it. Subsequent GUI object calls to GUI are delegated to swing. Returns the current (swing) scheme.

### *fromID (id)

Changes the current scheme and returns the new scheme.

#### Arguments:

id | A Symbol. The identifier of the scheme to use.

### *current

Returns the current scheme. This is useful for objects that, upon instantiation, wish to store the then-current scheme, so as to be able to consistently use the same scheme in future method calls.

NOTE: the caller shouldn't make any assumptions about the nature (the class) of the returned object, so that the actual implementation (an Event) may change in the future.

### *get (id)

Returns the scheme for a given identifier. Does not switch the current scheme.

#### Arguments:

id | A Symbol. The identifier of the scheme to retrieve, such as returned by calling `aScheme.id`.

### *set (aScheme)

Changes the current scheme.

#### Arguments:

aScheme | An instance of Symbol. The scheme to use as current scheme.

### *use (aScheme, func)

Executes a function body, temporarily setting the current GUI scheme. This is useful inside view's action functions in order to make this function use the GUI scheme that was originally used for the view of the action, even if the scheme has been switched meanwhile.

#### Arguments:

aScheme | The scheme to use during the function execution.
func | An Instance of Function.

### *useID (id, func)

Same as `use` but using a scheme's id as first argument.

#### Arguments:

id | The id of the scheme to use during the function execution.
func | A body to execute.

### *add (aScheme)

Registers a new scheme. This is typically called by external libraries in their startup procedure. If a scheme with the same identifier (`scheme.id`) exists, it is overwritten.

#### Arguments:

aScheme | The scheme to add.

### *doesNotUnderstand (selector ... args)

All method calls are mapped to the current scheme, so that for example `GUI.button` can be used and is delegated to the button association of the current scheme.

#### Arguments:

selector |
... args |

### *setSkin (skinName)

#### Arguments:

skinName |

### *scheme

A class variable. Returns the current scheme.

### *schemes

A class variable. Returns an IdentityDictionary of registered schemes.

### *skin

A class variable. Returns the current skin.

### *skins

A class variable. Returns an IdentityDictionary of registered skins.

### Inherited class methods

### Undocumented class methods

### *qt

## Instance Methods

### Inherited instance methods

helpfile source: /Applications/SuperCollider.app/Contents/Resources/HelpSource/Classes/GUI.schelp
link::Classes/GUI::
sc version: 3.8.0