Skip to content

Commit

Permalink
CVideo: refactored out custom SDL window state flags
Browse files Browse the repository at this point in the history
The function CVideo::window_state was the same as sdl::window::get_flags, except it handled
the custom state flags. The only slight semantic change is formally, the SDL_APPACTIVE encompassed
SDL_WINDOW_SHOWN && !SDL_WINDOW_MINIMIZED; however, it's very unlikely the former flag would be ever
set if the latter were as well.
  • Loading branch information
Vultraz committed Dec 6, 2016
1 parent bf86912 commit 5f3a0bb
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/controller_base.cpp
Expand Up @@ -133,7 +133,7 @@ void controller_base::process_keyup_event(const SDL_Event& /*event*/) {

bool controller_base::handle_scroll(int mousex, int mousey, int mouse_flags, double x_axis, double y_axis)
{
bool mouse_in_window = (CVideo::get_singleton().window_state() & SDL_APPMOUSEFOCUS) != 0
bool mouse_in_window = (CVideo::get_singleton().get_window()->get_flags() & SDL_WINDOW_MOUSE_FOCUS) != 0
|| preferences::get("scroll_when_mouse_outside", true);
int scroll_speed = preferences::scroll_speed();
int dx = 0, dy = 0;
Expand Down Expand Up @@ -276,7 +276,7 @@ void controller_base::play_slice(bool is_delay_enabled)

// be nice when window is not visible
// NOTE should be handled by display instead, to only disable drawing
if (is_delay_enabled && (CVideo::get_singleton().window_state() & SDL_APPACTIVE) == 0) {
if (is_delay_enabled && (CVideo::get_singleton().get_window()->get_flags() & SDL_WINDOW_SHOWN) == 0) {
CVideo::delay(200);
}

Expand Down
6 changes: 3 additions & 3 deletions src/desktop/notifications.cpp
Expand Up @@ -49,13 +49,13 @@ bool available() { return true; }

void send(const std::string& owner, const std::string& message, type t)
{
Uint8 app_state = CVideo::get_singleton().window_state();
Uint8 app_state = CVideo::get_singleton().get_window()->get_flags();

// Do not show notifications when the window is visible...
if ((app_state & SDL_APPACTIVE) != 0)
if ((app_state & SDL_WINDOW_SHOWN) != 0)
{
// ... and it has a focus.
if ((app_state & (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) != 0) {
if ((app_state & (SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_INPUT_FOCUS)) != 0) {
return;
}
}
Expand Down
28 changes: 0 additions & 28 deletions src/video.cpp
Expand Up @@ -351,34 +351,6 @@ bool CVideo::update_locked() const
return updatesLocked_ > 0;
}

Uint8 CVideo::window_state()
{
Uint8 state = 0;
Uint32 flags = 0;

if(!window) {
return state;
}

flags = SDL_GetWindowFlags(*window);
if ((flags & SDL_WINDOW_SHOWN) && !(flags & SDL_WINDOW_MINIMIZED)) {
state |= SDL_APPACTIVE;
}
if (flags & SDL_WINDOW_INPUT_FOCUS) {
state |= SDL_APPINPUTFOCUS;
}
if (flags & SDL_WINDOW_MOUSE_FOCUS) {
state |= SDL_APPMOUSEFOCUS;
}
if (flags & SDL_WINDOW_MAXIMIZED) {
state |= SDL_WINDOW_MAXIMIZED;
}
if (flags & SDL_WINDOW_FULLSCREEN_DESKTOP) {
state |= SDL_WINDOW_FULLSCREEN_DESKTOP;
}
return state;
}

void CVideo::set_window_title(const std::string& title)
{
assert(window);
Expand Down
10 changes: 0 additions & 10 deletions src/video.hpp
Expand Up @@ -24,11 +24,6 @@

class surface;

//possible flags when setting video modes
#define SDL_APPMOUSEFOCUS 0x01 /**< The app has mouse coverage */
#define SDL_APPINPUTFOCUS 0x02 /**< The app has input focus */
#define SDL_APPACTIVE 0x04 /**< The application is active */

SDL_Rect screen_area();

class CVideo {
Expand Down Expand Up @@ -149,11 +144,6 @@ class CVideo {
//this needs to be invoked immediately after a resize event or the game will crash.
void update_framebuffer();

/**
* Wrapper for CVideo::get_singleton().window_state.
*/
Uint8 window_state();

/**
* Sets the title of the main window.
*
Expand Down

0 comments on commit 5f3a0bb

Please sign in to comment.