GUI Windows and Slaves

jwatte's picture

A plug-in can be called upon to open a GUI representation of its parameters. While the support library will provide a default GUI for a plug-in that doesn't want to customize itself, most plug-ins want to do something fancier. To allow hosts to use modern rendering techniques (WPF, Quartz, etc), the display and interaction of an effect is done through a simple scene graph, rather than through immediate mode render commands. There is a library for hosts to use to implement this scene graph, to simplify host implementation (but use of that library is not required).

/* Note that the slave is not addressable, but the window is! */
class ItfWindowSlave : public ItfEventTarget
{
  public:
    /* The host will call Opened as the first call into the ItfWindowSlave. This will be before */
    /* the call to OpenWindow has returned. The ItfWindow pointer is the pointer that will */
    /* be returned from OpenWindow(). */
    virtual void    Opened(ItfWindow *window) = 0;
    /* Whenever the mouse enters the window after having been out, MouseEnter is called. */
    virtual void    MouseEnter() = 0;
    /* Whenever the mouse is over a different element than before, MouseOverElement() is called. */
    virtual void    MouseOverElement(ItfElement *elem) = 0;
    /* Whenever the mouse moves at least one pixel (but maybe more), MosueMove() is called. /*
          /* Coordinates are relative to window top-left. */
    virtual void    MouseMove(size32 x, size32 y, size32 buttons) = 0;
    /* Whenever the mouse button (any button) is pressed, MouseDown() is called. The position is */
    /* as per the previous call to MouseOverElement() and MouseMove(). */
    virtual void    MouseDown(size32 oldButtson, size32 newButtons) = 0;
    /* Whenever the mouse is released, MouseUp() is called with the old and new button mask. */
    virtual void    MouseUp(size32 oldButtson, size32 newButtons) = 0;
    /* Whenever the mouse moves out of the window (or the window becomes inactive), MouseLeave() is called. */
    virtual void    MouseLeave() = 0;
    /* If the window has capture, and loses it, CaptureLost() is called. */
    virtual void    CaptureLost() = 0;
    /* If the window is resizable, when the user starts resizing, BeginResize() will be called. */
    virtual void    BeginResize() = 0;
    /* If the window is resizable, while the user is resizing the window, UpdateResize() is called. */
    virtual void    UpdateResize() = 0;
    /* If the window is resizable, after the user has completed resizing, CommitResize() is called. */
    virtual void    CommitResize() = 0;
    /* If the window has focus, and loses it, FocusLost() is called. */
    virtual void    FocusLost() = 0;
    /* Whenever the window has focus and a key is pressed, KeyDown() is called. This does not include printable keys (as will be delivered through Type). */
    virtual void    KeyDown(size32 key, size32 buttons) = 0;
    /* Whenever the window has focus and a key is released, KeyUp() is called. */
    virtual void    KeyUp(size32 key, size32 buttons) = 0;
    /* Whenever the window has focus and text is typed, Type() is called. This does not include non-printable keys (like F-keys etc). */
    virtual void    Type(wchar_t const *text) = 0;
    /* Every once in a while, the window Idle() function will be called. */
    virtual void    Idle() = 0;
    /* When the window is finally closed. Closed() will be called. Typically inside a call to Close(), or as the result of a user click in the close button. */
    /* When Closed() has returned, the host will no longer call this ItfWindowSlave. */
    virtual void    Closed() = 0;
 
    virtual void   *Extension(wchar_t const *name) = 0;
};
 
/* Messages that go to the ItfWindow are dispatched to the ItfWindowSlave. */
class ItfWindow : public ItfAddressable
{
  public:
    /* Request a close of the window. */
    virtual void    Close() = 0;
    /* Find the slave of this window. */
    virtual ItfWindowSlave *
                    Slave() = 0;
    /* Resize the window to a given size. The size will be clipped to the min/max size specified on creation. */
    virtual void    Resize(size32 width, size32 height) = 0;
    /* Find out how big the window is now. */
    virtual void    Extent(size32 *ox, size32 *oy) = 0;
    /* Set the mouse capture. This means that all mouse move events will go to this window, even if outside the window bounds! */
    virtual void    SetCapture() = 0;
    /* Set the focus. This means that further typing will go to this window. */
    virtual void    SetFocus() = 0;
    /* Make a bitmap widget, which you can then fill with data and add to the window. */
    virtual ItfBitmap *
                    MakeBitmap(size32 width, size32 height) = 0;
    /* Make a text widget, which you can then add to the window, as well as re-set text on. */
    virtual ItfText *
                    MakeText(TextInfo const &info) = 0;
    /* Add a given element to the window. */
    virtual void    AddElement(ItfElement *widget, ItfElement *before = NULL) = 0;
    /* How many elements are in the window? */
    virtual size32  ElementCount() = 0;
    /* Return the element at a given index, or NULL. */
    virtual ItfElement *
                    Element(size32 index) = 0;
    /* Invalidate some part of the window, or the entire window */
    virtual void    Invalidate(ItfElement *elem = 0) = 0;
 
    virtual void *Extension(wchar_t const *name) = 0;
};
 
/* Configuration for a window, provided to the host when creating the window */
struct WindowConfig
{
  size64            StructSize;   //  sizeof(WindowConfig)
  wchar_t const    *Title;        //  The title of the window (0-terminated string)
  size32            MinWidth;     //  Minimum width of the window
  size32            MinHeight;    //  Minimum height of the window
  size32            MaxWidth;     //  Minimum width of the window. If <= MinWidth, not resizable horizontally
  size32            MaxHeight;    //  Maximum height of the widnow. If <= MinHeight, not resizable vertically
};