Back to index

libsfml  1.6+dfsg2
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
sf::priv::WindowImpl Class Reference

Abstract base class for OS-specific window implementation /////////////////////////////////////////////////////////. More...

#include <WindowImpl.hpp>

Inheritance diagram for sf::priv::WindowImpl:
Inheritance graph
[legend]
Collaboration diagram for sf::priv::WindowImpl:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual ~WindowImpl ()
 Destructor.
void AddListener (WindowListener *Listener)
 Add a listener to the window.
void RemoveListener (WindowListener *Listener)
 Remove a listener from the window.
void Initialize ()
 Initialize window's states that can't be done at construction.
unsigned int GetWidth () const
 Get the client width of the window.
unsigned int GetHeight () const
 Get the client height of the window.
virtual void SetActive (bool Active=true) const =0
 Activate of deactivate the window as the current target for rendering.
void SetJoystickThreshold (float Threshold)
 Change the joystick threshold, ie. the value below which no move event will be generated.
void DoEvents ()
 Process incoming events from operating system.
virtual void Display ()=0
 Display the window on screen.
virtual void UseVerticalSync (bool Enabled)=0
 Enable / disable vertical synchronization.
virtual void ShowMouseCursor (bool Show)=0
 Show or hide the mouse cursor.
virtual void SetCursorPosition (unsigned int Left, unsigned int Top)=0
 Change the position of the mouse cursor.
virtual void SetPosition (int Left, int Top)=0
 Change the position of the window on screen.
virtual void SetSize (unsigned int Width, unsigned int Height)=0
 Change the size of the rendering region of the window.
virtual void Show (bool State)=0
 Show or hide the window.
virtual void EnableKeyRepeat (bool Enabled)=0
 Enable or disable automatic key-repeat.
virtual void SetIcon (unsigned int Width, unsigned int Height, const Uint8 *Pixels)=0
 Change the window's icon.

Static Public Member Functions

static WindowImplNew ()
 Create a new window depending on the current OS.
static WindowImplNew (VideoMode Mode, const std::string &Title, unsigned long WindowStyle, WindowSettings &Params)
 Create a new window depending on the current OS.
static WindowImplNew (WindowHandle Handle, WindowSettings &Params)
 Create a new window depending on to the current OS.
static bool IsContextActive ()
 Check if there's an active context on the current thread.

Protected Member Functions

 WindowImpl ()
 Default constructor.
void SendEvent (const Event &EventToSend)
 Send an event to listeners (for derived classes only)

Static Protected Member Functions

static int EvaluateConfig (const VideoMode &Mode, const WindowSettings &Settings, int ColorBits, int DepthBits, int StencilBits, int Antialiasing)
 Evaluate a pixel format configuration. This functions can be used by implementations that have several valid formats and want to get the best one.

Protected Attributes

unsigned int myWidth
 Internal width of the window.
unsigned int myHeight
 Internal height of the window.

Private Member Functions

void ProcessJoystickEvents ()
 Read the joysticks state and generate the appropriate events.
virtual void ProcessEvents ()=0
 Process incoming events from operating system.

Private Attributes

std::set< WindowListener * > myListeners
 Array of listeners connected to the window.
Joystick myJoysticks [Joy::Count]
 Joysticks to observe.
JoystickState myJoyStates [Joy::Count]
 Current states of the joysticks.
float myJoyThreshold
 Joystick threshold (minimum motion for MOVE event to be generated)

Detailed Description

Abstract base class for OS-specific window implementation /////////////////////////////////////////////////////////.

Definition at line 51 of file WindowImpl.hpp.


Constructor & Destructor Documentation

Destructor.

Destructor /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 97 of file WindowImpl.cpp.

{
    // Nothing to do
}

Default constructor.

Default constructor /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 86 of file WindowImpl.cpp.

                       :
myWidth       (0),
myHeight      (0),
myJoyThreshold(0.1f)
{
}

Member Function Documentation

void sf::priv::WindowImpl::AddListener ( WindowListener *  Listener)

Add a listener to the window.

Add a listener to the window /////////////////////////////////////////////////////////.

Parameters:
Listener: Listener to add

/////////////////////////////////////////////////////////

Definition at line 106 of file WindowImpl.cpp.

{
    if (Listener)
        myListeners.insert(Listener);
}
virtual void sf::priv::WindowImpl::Display ( ) [pure virtual]

Display the window on screen.

/////////////////////////////////////////////////////////

Implemented in sf::priv::WindowImplCocoa, sf::priv::WindowImplX11, sf::priv::WindowImplWin32, and sf::priv::WindowImplXXX.

Process incoming events from operating system.

Process incoming events from operating system /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 167 of file WindowImpl.cpp.

{
    // Read the joysticks state and generate the appropriate events
    ProcessJoystickEvents();

    // Let the derived class process other events
    ProcessEvents();
}

Here is the call graph for this function:

virtual void sf::priv::WindowImpl::EnableKeyRepeat ( bool  Enabled) [pure virtual]

Enable or disable automatic key-repeat.

Parameters:
Enabled: True to enable, false to disable

/////////////////////////////////////////////////////////

Implemented in sf::priv::WindowImplCocoa, sf::priv::WindowImplX11, sf::priv::WindowImplXXX, and sf::priv::WindowImplWin32.

int sf::priv::WindowImpl::EvaluateConfig ( const VideoMode &  Mode,
const WindowSettings Settings,
int  ColorBits,
int  DepthBits,
int  StencilBits,
int  Antialiasing 
) [static, protected]

Evaluate a pixel format configuration. This functions can be used by implementations that have several valid formats and want to get the best one.

Evaluate a pixel format configuration. This functions can be used by implementations that have several valid formats and want to get the best one /////////////////////////////////////////////////////////.

Parameters:
Mode: Requested video mode
Settings: Requested additionnal settings
ColorBits: Color bits of the configuration to evaluate
DepthBits: Depth bits of the configuration to evaluate
StencilBits: Stencil bits of the configuration to evaluate
Antialiasing: Antialiasing level of the configuration to evaluate
Returns:
Score of the configuration : the lower the better

/////////////////////////////////////////////////////////

Definition at line 203 of file WindowImpl.cpp.

{
    return abs(static_cast<int>(Mode.BitsPerPixel          - ColorBits))   +
           abs(static_cast<int>(Settings.DepthBits         - DepthBits))   +
           abs(static_cast<int>(Settings.StencilBits       - StencilBits)) +
           abs(static_cast<int>(Settings.AntialiasingLevel - Antialiasing));
}

Here is the caller graph for this function:

unsigned int sf::priv::WindowImpl::GetHeight ( ) const

Get the client height of the window.

Get the client height of the window /////////////////////////////////////////////////////////.

Returns:
Height of the window in pixels

/////////////////////////////////////////////////////////

Definition at line 148 of file WindowImpl.cpp.

{
    return myHeight;
}
unsigned int sf::priv::WindowImpl::GetWidth ( ) const

Get the client width of the window.

Get the client width of the window /////////////////////////////////////////////////////////.

Returns:
Width of the window in pixels

/////////////////////////////////////////////////////////

Definition at line 139 of file WindowImpl.cpp.

{
    return myWidth;
}

Initialize window's states that can't be done at construction.

Initialize window's states that can't be done at construction /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Reimplemented in sf::priv::WindowImplX11.

Definition at line 125 of file WindowImpl.cpp.

{
    // Initialize the joysticks
    for (unsigned int i = 0; i < Joy::Count; ++i)
    {
        myJoysticks[i].Initialize(i);
        myJoyStates[i] = myJoysticks[i].UpdateState();
    }
}

Here is the call graph for this function:

Check if there's an active context on the current thread.

Check if there's an active context on the current thread /////////////////////////////////////////////////////////.

Returns:
True if there's a context bound to the current thread

/////////////////////////////////////////////////////////

Reimplemented in sf::priv::WindowImplCocoa, sf::priv::WindowImplX11, sf::priv::WindowImplWin32, and sf::priv::WindowImplXXX.

Definition at line 180 of file WindowImpl.cpp.

Create a new window depending on the current OS.

Create a new window depending on the current OS /////////////////////////////////////////////////////////.

Returns:
Pointer to the created window

/////////////////////////////////////////////////////////

Definition at line 59 of file WindowImpl.cpp.

{
    return new WindowImplType();
}
WindowImpl * sf::priv::WindowImpl::New ( VideoMode  Mode,
const std::string &  Title,
unsigned long  WindowStyle,
WindowSettings Params 
) [static]

Create a new window depending on the current OS.

Create a new window depending on the current OS /////////////////////////////////////////////////////////.

Parameters:
Mode: Video mode to use
Title: Title of the window
WindowStyle: Window style
Params: Creation parameters
Returns:
Pointer to the created window

/////////////////////////////////////////////////////////

Definition at line 68 of file WindowImpl.cpp.

{
    return new WindowImplType(Mode, Title, WindowStyle, Params);
}
WindowImpl * sf::priv::WindowImpl::New ( WindowHandle  Handle,
WindowSettings Params 
) [static]

Create a new window depending on to the current OS.

Create a new window depending on the current OS /////////////////////////////////////////////////////////.

Parameters:
Handle: Platform-specific handle of the control
Params: Creation parameters
Returns:
Pointer to the created window

/////////////////////////////////////////////////////////

Definition at line 77 of file WindowImpl.cpp.

{
    return new WindowImplType(Handle, Params);
}
virtual void sf::priv::WindowImpl::ProcessEvents ( ) [private, pure virtual]

Process incoming events from operating system.

/////////////////////////////////////////////////////////

Implemented in sf::priv::WindowImplCocoa, sf::priv::WindowImplX11, sf::priv::WindowImplXXX, and sf::priv::WindowImplWin32.

Here is the caller graph for this function:

Read the joysticks state and generate the appropriate events.

Read the joysticks state and generate the appropriate events /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 215 of file WindowImpl.cpp.

{
    for (unsigned int i = 0; i < Joy::Count; ++i)
    {
        // Copy the previous state of the joystick and get the new one
        JoystickState PreviousState = myJoyStates[i];
        myJoyStates[i] = myJoysticks[i].UpdateState();

        // Axis
        for (unsigned int j = 0; j < Joy::AxisCount; ++j)
        {
            Joy::Axis Axis = static_cast<Joy::Axis>(j);
            if (myJoysticks[i].HasAxis(Axis))
            {
                float PrevPos = PreviousState.Axis[j];
                float CurrPos = myJoyStates[i].Axis[j];
                if (fabs(CurrPos - PrevPos) >= myJoyThreshold)
                {
                    Event Event;
                    Event.Type               = Event::JoyMoved;
                    Event.JoyMove.JoystickId = i;
                    Event.JoyMove.Axis       = Axis;
                    Event.JoyMove.Position   = CurrPos;
                    SendEvent(Event);
                }
            }
        }

        // Buttons
        for (unsigned int j = 0; j < myJoysticks[i].GetButtonsCount(); ++j)
        {
            bool PrevPressed = PreviousState.Buttons[j];
            bool CurrPressed = myJoyStates[i].Buttons[j];

            if ((!PrevPressed && CurrPressed) || (PrevPressed && !CurrPressed))
            {
                Event Event;
                Event.Type                 = CurrPressed ? Event::JoyButtonPressed : Event::JoyButtonReleased;
                Event.JoyButton.JoystickId = i;
                Event.JoyButton.Button     = j;
                SendEvent(Event);
            }
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sf::priv::WindowImpl::RemoveListener ( WindowListener *  Listener)

Remove a listener from the window.

Remove a listener from the window /////////////////////////////////////////////////////////.

Parameters:
Listener: Listener to remove

/////////////////////////////////////////////////////////

Definition at line 116 of file WindowImpl.cpp.

{
    myListeners.erase(Listener);
}
void sf::priv::WindowImpl::SendEvent ( const Event EventToSend) [protected]

Send an event to listeners (for derived classes only)

Send an event to listeners /////////////////////////////////////////////////////////.

Parameters:
EventToSend: Event to send

/////////////////////////////////////////////////////////

Definition at line 189 of file WindowImpl.cpp.

{
    for (std::set<WindowListener*>::iterator i = myListeners.begin(); i != myListeners.end(); ++i)
    {
        (*i)->OnEvent(EventToSend);
    }
}

Here is the caller graph for this function:

virtual void sf::priv::WindowImpl::SetActive ( bool  Active = true) const [pure virtual]

Activate of deactivate the window as the current target for rendering.

Parameters:
Active: True to activate, false to deactivate (true by default)

/////////////////////////////////////////////////////////

Implemented in sf::priv::WindowImplCocoa, sf::priv::WindowImplX11, sf::priv::WindowImplWin32, and sf::priv::WindowImplXXX.

virtual void sf::priv::WindowImpl::SetCursorPosition ( unsigned int  Left,
unsigned int  Top 
) [pure virtual]

Change the position of the mouse cursor.

Parameters:
Left: Left coordinate of the cursor, relative to the window
Top: Top coordinate of the cursor, relative to the window

/////////////////////////////////////////////////////////

Implemented in sf::priv::WindowImplCocoa, sf::priv::WindowImplX11, sf::priv::WindowImplXXX, and sf::priv::WindowImplWin32.

virtual void sf::priv::WindowImpl::SetIcon ( unsigned int  Width,
unsigned int  Height,
const Uint8 *  Pixels 
) [pure virtual]

Change the window's icon.

Parameters:
Width: Icon's width, in pixels
Height: Icon's height, in pixels
Pixels: Pointer to the pixels in memory, format must be RGBA 32 bits

/////////////////////////////////////////////////////////

Implemented in sf::priv::WindowImplCocoa, sf::priv::WindowImplX11, sf::priv::WindowImplXXX, and sf::priv::WindowImplWin32.

void sf::priv::WindowImpl::SetJoystickThreshold ( float  Threshold)

Change the joystick threshold, ie. the value below which no move event will be generated.

Change the joystick threshold, ie. the value below which no move event will be generated /////////////////////////////////////////////////////////.

Parameters:
Threshold: New threshold, in range [0, 100]

/////////////////////////////////////////////////////////

Definition at line 158 of file WindowImpl.cpp.

{
    myJoyThreshold = Threshold;
}
virtual void sf::priv::WindowImpl::SetPosition ( int  Left,
int  Top 
) [pure virtual]

Change the position of the window on screen.

Parameters:
Left: Left position
Top: Top position

/////////////////////////////////////////////////////////

Implemented in sf::priv::WindowImplCocoa, sf::priv::WindowImplX11, sf::priv::WindowImplXXX, and sf::priv::WindowImplWin32.

virtual void sf::priv::WindowImpl::SetSize ( unsigned int  Width,
unsigned int  Height 
) [pure virtual]

Change the size of the rendering region of the window.

Parameters:
Width: New width
Height: New height

/////////////////////////////////////////////////////////

Implemented in sf::priv::WindowImplCocoa, sf::priv::WindowImplX11, sf::priv::WindowImplXXX, and sf::priv::WindowImplWin32.

virtual void sf::priv::WindowImpl::Show ( bool  State) [pure virtual]

Show or hide the window.

Parameters:
State: True to show, false to hide

/////////////////////////////////////////////////////////

Implemented in sf::priv::WindowImplCocoa, sf::priv::WindowImplX11, sf::priv::WindowImplXXX, and sf::priv::WindowImplWin32.

virtual void sf::priv::WindowImpl::ShowMouseCursor ( bool  Show) [pure virtual]

Show or hide the mouse cursor.

Parameters:
Show: True to show, false to hide

/////////////////////////////////////////////////////////

Implemented in sf::priv::WindowImplCocoa, sf::priv::WindowImplX11, sf::priv::WindowImplXXX, and sf::priv::WindowImplWin32.

virtual void sf::priv::WindowImpl::UseVerticalSync ( bool  Enabled) [pure virtual]

Enable / disable vertical synchronization.

Parameters:
Enabled: True to enable v-sync, false to deactivate

/////////////////////////////////////////////////////////

Implemented in sf::priv::WindowImplCocoa, sf::priv::WindowImplX11, sf::priv::WindowImplXXX, and sf::priv::WindowImplWin32.


Member Data Documentation

unsigned int sf::priv::WindowImpl::myHeight [protected]

Internal height of the window.

Definition at line 277 of file WindowImpl.hpp.

Current states of the joysticks.

Definition at line 298 of file WindowImpl.hpp.

Joysticks to observe.

Definition at line 297 of file WindowImpl.hpp.

Joystick threshold (minimum motion for MOVE event to be generated)

Definition at line 299 of file WindowImpl.hpp.

std::set<WindowListener*> sf::priv::WindowImpl::myListeners [private]

Array of listeners connected to the window.

Definition at line 296 of file WindowImpl.hpp.

unsigned int sf::priv::WindowImpl::myWidth [protected]

Internal width of the window.

Definition at line 276 of file WindowImpl.hpp.


The documentation for this class was generated from the following files: