class EE::Window::Window

Overview

#include <window.hpp>

class Window {
public:
    // typedefs

    typedef std::function<void(Window*)> WindowResizeCallback;
    typedef std::function<bool(Window*)> WindowRequestCloseCallback;
    typedef std::function<void(Window*)> WindowQuitCallback;

    // enums

    enum MessageBoxType;

    // classes

    class FrameData;

    // construction

    Window(WindowSettings Settings, ContextSettings Context, Clipboard* Clipboard, Input* Input, CursorManager* CursorManager);
    virtual ~Window();

    // methods

    virtual bool create(WindowSettings Settings, ContextSettings Context) = 0;
    virtual void makeCurrent() = 0;
    virtual Uint32 getWindowID() = 0;
    virtual void toggleFullscreen() = 0;
    virtual void setTitle(const std::string& title) = 0;
    virtual std::string getTitle();
    virtual bool setIcon(const std::string& path) = 0;
    virtual void minimize();
    virtual void maximize();
    virtual bool isMaximized();
    virtual void hide();
    virtual void raise();
    virtual void flash(WindowFlashOperation op);
    virtual void show();
    virtual void setPosition(int Left, int Top);
    virtual Vector2i getPosition();
    virtual void setDefaultContext();
    virtual bool isActive() = 0;
    virtual bool isVisible() = 0;
    virtual bool hasFocus() = 0;
    virtual bool hasInputFocus() = 0;
    virtual bool hasMouseFocus() = 0;
    virtual void setSize(Uint32 Width, Uint32 Height);
    virtual void setSize(Uint32 Width, Uint32 Height, bool isWindowed) = 0;
    virtual Sizei getSize();
    Vector2f getCenter();
    virtual std::vector<DisplayMode> getDisplayModes() const = 0;
    virtual void setGamma(Float Red, Float Green, Float Blue) = 0;
    virtual void setCurrentContext(eeWindowContex Context);
    virtual eeWindowContex getContext() const;
    virtual eeWindowHandle getWindowHandler() = 0;
    virtual void clear();
    virtual void display(bool clear = false);
    virtual const System::Time& getElapsed() const;
    virtual Uint32 getFPS() const;
    virtual bool isWindowed() const;
    virtual bool isResizeable() const;
    virtual const Uint32& getWidth() const;
    virtual const Uint32& getHeight() const;
    virtual const Sizei& getDesktopResolution();
    virtual void centerToDisplay();
    virtual Rect getBorderSize();
    virtual Float getScale();
    bool isRunning() const;
    bool isOpen() const;
    virtual void close();
    void setView(const View& view, bool forceRefresh = false);
    const View& getView() const;
    const View& getDefaultView() const;
    void setup2D(const bool& KeepView = true);
    void set2DProjection(const Uint32& Width, const Uint32& Height);
    void setProjection(const Transform& transform);
    void setViewport(const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height);
    Rect getViewport(const View& view);
    void setClearColor(const RGB& Color);
    RGB getClearColor() const;
    bool takeScreenshot(std::string filepath = "", const Image::SaveType& Format = Image::SaveType::SAVE_TYPE_PNG);
    const WindowInfo* getWindowInfo() const;
    void setFrameRateLimit(const Uint32& setFrameRateLimit);
    Uint32 getFrameRateLimit();
    Clipboard* getClipboard() const;
    Input* getInput() const;
    CursorManager* getCursorManager() const;
    Uint32 pushResizeCallback(const WindowResizeCallback& cb);
    void popResizeCallback(const Uint32& CallbackId);
    virtual void startOnScreenKeyboard();
    virtual void stopOnScreenKeyboard();
    virtual bool isOnScreenKeyboardActive() const;
    virtual void startTextInput();
    virtual bool isTextInputActive() const;
    virtual void stopTextInput();
    virtual void setTextInputRect(const Rect& rect);
    virtual void clearComposition();
    virtual bool hasScreenKeyboardSupport();
    virtual bool isScreenKeyboardShown();
    virtual bool isThreadedGLContext();
    virtual void setGLContextThread();
    virtual void unsetGLContextThread();
    void runMainLoop(std::function<void()> func, int fps = -1);
    virtual int getCurrentDisplayIndex();
    Vector2f mapPixelToCoords(const Vector2i& point);
    Vector2f mapPixelToCoords(const Vector2i& point, const View& view);
    Vector2i mapCoordsToPixel(const Vector2f& point);
    Vector2i mapCoordsToPixel(const Vector2f& point, const View& view);
    void setCloseRequestCallback(const WindowRequestCloseCallback& closeRequestCallback);
    void setQuitCallback(const WindowQuitCallback& quitCallback);
    const System::Time& getSleepTimePerSecond() const;
    const System::Time& getRenderTimePerSecond() const;
    const Sizei& getLastWindowedSize() const;
    virtual bool hasNativeMessageBox() const;
    virtual bool showMessageBox(const MessageBoxType& type, const std::string& title, const std::string& message);
    InputMethod& getIME();
    const std::function<void()>& getMainLoop();
};

Detailed Documentation

Methods

virtual bool create(WindowSettings Settings, ContextSettings Context) = 0

Creates a new window and GL context

virtual void makeCurrent() = 0

Bind the OpenGL context to the current window

virtual void toggleFullscreen() = 0

Toogle the screen to Fullscreen, if it’s in fullscreen toogle to windowed mode.

virtual void setTitle(const std::string& title) = 0

Set the window title

virtual std::string getTitle()

Returns:

The window title

virtual bool setIcon(const std::string& path) = 0

Set the Window icon

virtual void minimize()

This will attempt to iconify/minimize the window.

virtual void maximize()

Maximize the Window

virtual bool isMaximized()

Returns:

true if the window is maximized

virtual void hide()

This will attempt to hide the window

virtual void raise()

This will attempt to raise the window

virtual void flash(WindowFlashOperation op)

Request a window to demand attention from the user.

virtual void show()

This will attempt to show the window

virtual void setPosition(int Left, int Top)

This will attemp to move the window over the desktop to the position

virtual Vector2i getPosition()

Returns:

The Current Window Position

virtual void setDefaultContext()

Set as current context the default context ( the context used for the window creation )

virtual bool isActive() = 0

Returns:

If the current window is active. This means that the window hasInputFocus() and hasMouseFocus().

virtual bool isVisible() = 0

Returns:

If the current window is visible

virtual bool hasFocus() = 0

Returns:

If the current window has focus (same as hasInputFocus() or(||) hasMouseFocus())

virtual bool hasInputFocus() = 0

Returns:

If the current window has input focus

virtual bool hasMouseFocus() = 0

Returns:

If the current window has input focus

virtual void setSize(Uint32 Width, Uint32 Height)

Set the size of the window for a windowed window

virtual void setSize(Uint32 Width, Uint32 Height, bool isWindowed) = 0

Change the window size or the screen resolution

Parameters:

Width

New screen width

Height

New screen height

isWindowed

Windowed or Fullscreen

virtual Sizei getSize()

Returns:

The window size

Vector2f getCenter()

Returns:

The window center point

virtual std::vector<DisplayMode> getDisplayModes() const = 0

Returns:

The resolutions that support the video card

virtual void setGamma(Float Red, Float Green, Float Blue) = 0

Set the Screen Gamma. Default is (1,1,1). Accept values between 0.1 and 10.

virtual void setCurrentContext(eeWindowContex Context)

The the OpenGL context as the current context

virtual eeWindowContex getContext() const

Returns:

The current OpenGL context

virtual eeWindowHandle getWindowHandler() = 0

Returns:

The window handler

virtual void clear()

Clear the window back buffer This function is usually called once every frame, to clear the previous frame content.

virtual void display(bool clear = false)

Render the Scene to Screen

Parameters:

clear

Clear after swapping buffers? It will not work if the target platform is Emscripten. Since there’s no swap buffers.

virtual const System::Time& getElapsed() const

Returns:

The elapsed time for the last frame rendered

virtual Uint32 getFPS() const

Returns:

The current frames per second of the screen

virtual bool isWindowed() const

Returns:

If the screen is windowed

virtual bool isResizeable() const

Returns:

If the main window is resizeable

virtual const Uint32& getWidth() const

Returns:

The Window Width

virtual const Uint32& getHeight() const

Returns:

The Window Height

virtual const Sizei& getDesktopResolution()

Returns:

The current desktop resolution

virtual void centerToDisplay()

Center the window to the desktop ( if windowed )

virtual Rect getBorderSize()

Returns:

The window borders size

virtual Float getScale()

Returns:

The size of the pixel in screen coordinates. This is the device scale factor.

bool isRunning() const

Returns:

If the aplication is running returns true ( If you Init correctly the window and is running ).

bool isOpen() const

Returns:

If the window was created

virtual void close()

Close the window if is running

void setView(const View& view, bool forceRefresh = false)

Set the current active view

Parameters:

view

New view to use (pass GetDefaultView() to set the default view)

forceRefresh

Forces the view refresh even if is the same as the last one.

const View& getView() const

Get the current view

const View& getDefaultView() const

Get the default view of the window

void setup2D(const bool& KeepView = true)

This will set the default rendering states and view to render in 2D mode

void set2DProjection(const Uint32& Width, const Uint32& Height)

Set a new 2D projection matrix

void setProjection(const Transform& transform)

Set a new projection matrix

void setViewport(const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height)

Set the current Viewport ( and creates a new ortho proyection if needed )

Rect getViewport(const View& view)

Returns:

The viewport in pixels of the view

void setClearColor(const RGB& Color)

Set the window background color

RGB getClearColor() const

Returns:

The background clear color

bool takeScreenshot(std::string filepath = "", const Image::SaveType& Format = Image::SaveType::SAVE_TYPE_PNG)

Captures the window front buffer and saves it to disk.

You have to call it before Display, and after render all the objects.

If the file path is empty will save the files like 0001.bmp, and will check if the file exists, otherwise will create 0002.bmp, and so on…

You can set only the path to save the files, like “screenshots/”

Returns:

False if failed, otherwise returns True

const WindowInfo* getWindowInfo() const

Returns:

The pointer to the Window Info ( read only )

void setFrameRateLimit(const Uint32& setFrameRateLimit)

Set a frame per second limit. It’s not 100 % accurate.

Uint32 getFrameRateLimit()

Get a frame per second limit.

Clipboard* getClipboard() const

Returns:

The clipboard manager

Input* getInput() const

Returns:

The input manager

CursorManager* getCursorManager() const

Returns:

The cursor manager

Uint32 pushResizeCallback(const WindowResizeCallback& cb)

Push a new window resize callback.

Returns:

The Callback Id

void popResizeCallback(const Uint32& CallbackId)

Pop the callback id indicated.

virtual void startOnScreenKeyboard()

Show the on-screen keyboard if supported.

virtual void stopOnScreenKeyboard()

Hide the on-screen keyboard if supported.

virtual bool isOnScreenKeyboardActive() const

Returns:

True if on-screen keyboard is active.

virtual void startTextInput()

Start accepting Unicode text input events.

See also:

stopTextInput()

setTextInputRect()

hasScreenKeyboardSupport()

virtual bool isTextInputActive() const

Return whether or not Unicode text input events are enabled.

See also:

startTextInput()

stopTextInput()

virtual void stopTextInput()

Stop receiving any text input events.

See also:

startTextInput()

hasScreenKeyboardSupport()

virtual void setTextInputRect(const Rect& rect)

Set the rectangle used to type Unicode text inputs. This is used as a hint for IME and on-screen keyboard placement.

See also:

startTextInput()

virtual void clearComposition()

Dismiss the composition window/IME without disabling the subsystem.

See also:

startTextInput

stopTextInput

virtual bool hasScreenKeyboardSupport()

Returns whether the platform has some screen keyboard support.

Note

Not all screen keyboard functions are supported on all platforms.

Returns:

true if some keyboard support is available else false.

See also:

isScreenKeyboardShown()

virtual bool isScreenKeyboardShown()

Returns whether the screen keyboard is shown for given window.

Returns:

true if screen keyboard is shown else false.

See also:

hasScreenKeyboardSupport()

virtual bool isThreadedGLContext()

Returns:

True if the current window support a threaded GL Context. This means that supports OpenGL Shared Contexts ( multithreaded opengl contexts ). * Only supported with SDL2 backend.

virtual void setGLContextThread()

Activates the shared GL context in the current thread.

virtual void unsetGLContextThread()

Deactviates the shared GL context in the current thread.

void runMainLoop(std::function<void()> func, int fps = -1)

Runs the main loop function passed as parameter

Parameters:

func

The main loop function

fps

The desired FPS ( 0 = infinite, < 0 keep current setting )

virtual int getCurrentDisplayIndex()

Returns:

The current display index.

const System::Time& getSleepTimePerSecond() const

In case of a frame rate limit is set, this will return the time spent sleeping per second.

const System::Time& getRenderTimePerSecond() const

In case of a frame rate limit is set, this will return the time spent doing work/rendering per second.

const Sizei& getLastWindowedSize() const

Returns:

The last windowed size of the window

virtual bool hasNativeMessageBox() const

Returns:

True if implements native message boxes

virtual bool showMessageBox(const MessageBoxType& type, const std::string& title, const std::string& message)

Shows a native message box.

Returns:

True if message box was shown