Skip to content

Commit

Permalink
Constness clean-up in Window class.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpartanJ committed Dec 22, 2024
1 parent 60784d7 commit d96a505
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 85 deletions.
58 changes: 30 additions & 28 deletions include/eepp/window/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class EE_API Window {
/** Bind the OpenGL context to the current window */
virtual void makeCurrent() = 0;

virtual Uint32 getWindowID() = 0;
virtual Uint32 getWindowID() const = 0;

/** Toogle the screen to Fullscreen, if it's in fullscreen toogle to windowed mode. */
virtual void toggleFullscreen() = 0;
Expand All @@ -179,7 +179,7 @@ class EE_API Window {
virtual void setTitle( const std::string& title ) = 0;

/** @return The window title*/
virtual std::string getTitle();
virtual const std::string& getTitle() const;

/** Set the Window icon */
virtual bool setIcon( const std::string& path ) = 0;
Expand All @@ -191,10 +191,10 @@ class EE_API Window {
virtual void maximize();

/** @return true if the window is maximized */
virtual bool isMaximized();
virtual bool isMaximized() const;

/** @return true if the window is minimized */
virtual bool isMinimized();
virtual bool isMinimized() const;

/** This will attempt to hide the window */
virtual void hide();
Expand All @@ -215,26 +215,26 @@ class EE_API Window {
virtual void setPosition( int Left, int Top );

/** @return The Current Window Position */
virtual Vector2i getPosition();
virtual Vector2i getPosition() const;

/** Set as current context the default context ( the context used for the window creation ) */
virtual void setDefaultContext();

/** @return If the current window is active. This means that the window hasInputFocus() and
* hasMouseFocus(). */
virtual bool isActive() = 0;
virtual bool isActive() const = 0;

/** @return If the current window is visible */
virtual bool isVisible() = 0;
virtual bool isVisible() const = 0;

/** @return If the current window has focus (same as hasInputFocus() or(||) hasMouseFocus()) */
virtual bool hasFocus() = 0;
virtual bool hasFocus() const = 0;

/** @return If the current window has input focus */
virtual bool hasInputFocus() = 0;
virtual bool hasInputFocus() const = 0;

/** @return If the current window has input focus */
virtual bool hasMouseFocus() = 0;
virtual bool hasMouseFocus() const = 0;

/** Set the size of the window for a windowed window */
virtual void setSize( Uint32 Width, Uint32 Height );
Expand All @@ -247,15 +247,15 @@ class EE_API Window {
virtual void setSize( Uint32 Width, Uint32 Height, bool isWindowed ) = 0;

/** @return The window size in pixels */
virtual Sizei getSize();
virtual Sizei getSize() const;

/** @return The window size in screen coordinates (screen coordinates is size in pixels /
* scale).
*/
virtual Sizei getSizeInScreenCoordinates();
virtual Sizei getSizeInScreenCoordinates() const;

/** @return The window center point */
Vector2f getCenter();
Vector2f getCenter() const;

/** @return The resolutions that support the video card */
virtual std::vector<DisplayMode> getDisplayModes() const = 0;
Expand All @@ -270,7 +270,7 @@ class EE_API Window {
virtual eeWindowContex getContext() const;

/** @return The window handler */
virtual eeWindowHandle getWindowHandler() = 0;
virtual eeWindowHandle getWindowHandler() const = 0;

/** @brief Clear the window back buffer
This function is usually called once every frame, to clear the previous frame content.
Expand Down Expand Up @@ -302,13 +302,13 @@ class EE_API Window {
virtual const Uint32& getHeight() const;

/** @return The current desktop resolution */
virtual const Sizei& getDesktopResolution();
virtual const Sizei& getDesktopResolution() const;

/** Center the window to the desktop ( if windowed ) */
virtual void centerToDisplay();

/** @return The window borders size */
virtual Rect getBorderSize();
virtual Rect getBorderSize() const;

/** @return The size of the pixel in screen coordinates. This is the device scale factor. */
virtual Float getScale() const;
Expand Down Expand Up @@ -348,7 +348,7 @@ class EE_API Window {
void setViewport( const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height );

/** @return The viewport in pixels of the view */
Rect getViewport( const View& view );
Rect getViewport( const View& view ) const;

/** Set the window background color */
void setClearColor( const RGB& Color );
Expand All @@ -373,7 +373,7 @@ class EE_API Window {
void setFrameRateLimit( const Uint32& setFrameRateLimit );

/** Get a frame per second limit. */
Uint32 getFrameRateLimit();
Uint32 getFrameRateLimit() const;

/** @return The clipboard manager */
Clipboard* getClipboard() const;
Expand Down Expand Up @@ -449,20 +449,20 @@ class EE_API Window {
*
* @sa isScreenKeyboardShown()
*/
virtual bool hasScreenKeyboardSupport();
virtual bool hasScreenKeyboardSupport() const;

/**
* @brief Returns whether the screen keyboard is shown for given window.
* @return true if screen keyboard is shown else false.
*
* @sa hasScreenKeyboardSupport()
*/
virtual bool isScreenKeyboardShown();
virtual bool isScreenKeyboardShown() const;

/** @return 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 bool isThreadedGLContext();
virtual bool isThreadedGLContext() const;

/** Activates the shared GL context in the current thread. */
virtual void setGLContextThread();
Expand All @@ -476,15 +476,15 @@ class EE_API Window {
void runMainLoop( std::function<void()> func, int fps = -1 );

/** @return The current display index. */
virtual int getCurrentDisplayIndex();
virtual int getCurrentDisplayIndex() const;

Vector2f mapPixelToCoords( const Vector2i& point );
Vector2f mapPixelToCoords( const Vector2i& point ) const;

Vector2f mapPixelToCoords( const Vector2i& point, const View& view );
Vector2f mapPixelToCoords( const Vector2i& point, const View& view ) const;

Vector2i mapCoordsToPixel( const Vector2f& point );
Vector2i mapCoordsToPixel( const Vector2f& point ) const;

Vector2i mapCoordsToPixel( const Vector2f& point, const View& view );
Vector2i mapCoordsToPixel( const Vector2f& point, const View& view ) const;

void setCloseRequestCallback( const WindowRequestCloseCallback& closeRequestCallback );

Expand Down Expand Up @@ -518,13 +518,15 @@ class EE_API Window {

InputMethod& getIME();

const std::function<void()>& getMainLoop() { return mMainLoop; }
const InputMethod& getIME() const;

const std::function<void()>& getMainLoop() const;

protected:
friend class Engine;
friend class Input;

WindowInfo mWindow;
mutable WindowInfo mWindow;
Clipboard* mClipboard;
Input* mInput;
CursorManager* mCursorManager;
Expand Down
34 changes: 17 additions & 17 deletions src/eepp/window/backend/SDL2/windowsdl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ bool WindowSDL::create( WindowSettings Settings, ContextSettings Context ) {
return true;
}

Uint32 WindowSDL::getWindowID() {
Uint32 WindowSDL::getWindowID() const {
return mID;
}

Expand All @@ -440,7 +440,7 @@ void WindowSDL::setCurrent() {
makeCurrent();
}

bool WindowSDL::isThreadedGLContext() {
bool WindowSDL::isThreadedGLContext() const {
#ifdef SDL2_THREADED_GLCONTEXT
return mWindow.ContextConfig.SharedGLContext;
#else
Expand All @@ -458,7 +458,7 @@ void WindowSDL::unsetGLContextThread() {
mGLContextMutex.unlock();
}

int WindowSDL::getCurrentDisplayIndex() {
int WindowSDL::getCurrentDisplayIndex() const {
int index = SDL_GetWindowDisplayIndex( mSDLWindow );

if ( index < 0 ) {
Expand Down Expand Up @@ -529,26 +529,26 @@ void WindowSDL::setTitle( const std::string& title ) {
}
}

bool WindowSDL::isActive() {
bool WindowSDL::isActive() const {
Uint32 flags = SDL_GetWindowFlags( mSDLWindow );
return 0 != ( ( flags & SDL_WINDOW_INPUT_FOCUS ) && ( flags & SDL_WINDOW_MOUSE_FOCUS ) );
}

bool WindowSDL::isVisible() {
bool WindowSDL::isVisible() const {
Uint32 flags = SDL_GetWindowFlags( mSDLWindow );
return 0 != ( ( flags & SDL_WINDOW_SHOWN ) && !( flags & SDL_WINDOW_MINIMIZED ) );
}

bool WindowSDL::hasFocus() {
bool WindowSDL::hasFocus() const {
return 0 != ( SDL_GetWindowFlags( mSDLWindow ) &
( SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS ) );
}

bool WindowSDL::hasInputFocus() {
bool WindowSDL::hasInputFocus() const {
return 0 != ( SDL_GetWindowFlags( mSDLWindow ) & ( SDL_WINDOW_INPUT_FOCUS ) );
}

bool WindowSDL::hasMouseFocus() {
bool WindowSDL::hasMouseFocus() const {
return 0 != ( SDL_GetWindowFlags( mSDLWindow ) & ( SDL_WINDOW_MOUSE_FOCUS ) );
}

Expand Down Expand Up @@ -693,7 +693,7 @@ void WindowSDL::setGamma( Float Red, Float Green, Float Blue ) {
SDL_SetWindowGammaRamp( mSDLWindow, red_ramp, green_ramp, blue_ramp );
}

eeWindowHandle WindowSDL::getWindowHandler() {
eeWindowHandle WindowSDL::getWindowHandler() const {
#ifdef EE_USE_WMINFO
if ( NULL != mWMinfo ) {
return mWMinfo->getWindowHandler();
Expand Down Expand Up @@ -773,11 +773,11 @@ void WindowSDL::maximize() {
SDL_MaximizeWindow( mSDLWindow );
}

bool WindowSDL::isMaximized() {
bool WindowSDL::isMaximized() const {
return SDL_GetWindowFlags( mSDLWindow ) & SDL_WINDOW_MAXIMIZED;
}

bool WindowSDL::isMinimized() {
bool WindowSDL::isMinimized() const {
return SDL_GetWindowFlags( mSDLWindow ) & SDL_WINDOW_MINIMIZED;
}

Expand Down Expand Up @@ -814,27 +814,27 @@ void WindowSDL::setPosition( int Left, int Top ) {
SDL_SetWindowPosition( mSDLWindow, Left, Top );
}

Vector2i WindowSDL::getPosition() {
Vector2i WindowSDL::getPosition() const {
Vector2i p;

SDL_GetWindowPosition( mSDLWindow, &p.x, &p.y );

return p;
}

void WindowSDL::updateDesktopResolution() {
void WindowSDL::updateDesktopResolution() const {
SDL_DisplayMode dpm;
SDL_GetDesktopDisplayMode( SDL_GetWindowDisplayIndex( mSDLWindow ), &dpm );

mWindow.DesktopResolution = Sizei( dpm.w, dpm.h );
}

const Sizei& WindowSDL::getDesktopResolution() {
const Sizei& WindowSDL::getDesktopResolution() const {
updateDesktopResolution();
return Window::getDesktopResolution();
}

Rect WindowSDL::getBorderSize() {
Rect WindowSDL::getBorderSize() const {
Rect bordersSize;
SDL_GetWindowBordersSize( mSDLWindow, &bordersSize.Top, &bordersSize.Left, &bordersSize.Bottom,
&bordersSize.Right );
Expand Down Expand Up @@ -939,11 +939,11 @@ void WindowSDL::clearComposition() {
#endif
}

bool WindowSDL::hasScreenKeyboardSupport() {
bool WindowSDL::hasScreenKeyboardSupport() const {
return SDL_TRUE == SDL_HasScreenKeyboardSupport();
}

bool WindowSDL::isScreenKeyboardShown() {
bool WindowSDL::isScreenKeyboardShown() const {
return SDL_TRUE == SDL_IsScreenKeyboardShown( mSDLWindow );
}

Expand Down
Loading

0 comments on commit d96a505

Please sign in to comment.