Skip to content

Commit

Permalink
Merge pull request #5904 from bparker06/opacity
Browse files Browse the repository at this point in the history
Add menu setting for window opacity
  • Loading branch information
inactive123 committed Dec 11, 2017
2 parents 621d89c + d53dbbf commit 767a1f3
Show file tree
Hide file tree
Showing 17 changed files with 258 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Makefile.common
Expand Up @@ -202,6 +202,7 @@ OBJ += frontend/frontend.o \
$(LIBRETRO_COMM_DIR)/audio/audio_mixer.o \
input/input_driver.o \
gfx/video_coord_array.o \
gfx/video_display_server.o \
gfx/video_driver.o \
camera/camera_driver.o \
wifi/wifi_driver.o \
Expand Down Expand Up @@ -248,6 +249,7 @@ OBJ += frontend/frontend.o \
camera/drivers/nullcamera.o \
wifi/drivers/nullwifi.o \
gfx/drivers/nullgfx.o \
gfx/display_servers/dispserv_null.o \
audio/drivers/nullaudio.o \
input/drivers/nullinput.o \
input/drivers_hid/null_hid.o \
Expand Down Expand Up @@ -1551,6 +1553,7 @@ ifneq ($(findstring Win32,$(OS)),)
OBJ += gfx/drivers/gdi_gfx.o \
gfx/drivers_context/gdi_ctx.o \
gfx/drivers_font/gdi_font.o \
gfx/display_servers/dispserv_win32.o \
menu/drivers_display/menu_display_gdi.o

LIBS += -lmsimg32 -lhid -lsetupapi
Expand Down
5 changes: 5 additions & 0 deletions config.def.h
Expand Up @@ -115,6 +115,11 @@ static const unsigned window_y = 0;
static const unsigned fullscreen_x = 0;
static const unsigned fullscreen_y = 0;

/* Amount of transparency to use for the main window.
* 1 is the most transparent while 100 is opaque.
*/
static const unsigned window_opacity = 100;

#if defined(RARCH_CONSOLE) || defined(__APPLE__)
static const bool load_dummy_on_core_shutdown = false;
#else
Expand Down
1 change: 1 addition & 0 deletions configuration.c
Expand Up @@ -1378,6 +1378,7 @@ static struct config_uint_setting *populate_settings_uint(settings_t *settings,
SETTING_UINT("video_fullscreen_y", &settings->uints.video_fullscreen_y, true, fullscreen_y, false);
SETTING_UINT("video_window_x", &settings->uints.video_window_x, true, fullscreen_x, false);
SETTING_UINT("video_window_y", &settings->uints.video_window_y, true, fullscreen_y, false);
SETTING_UINT("video_window_opacity", &settings->uints.video_window_opacity, true, window_opacity, false);
#ifdef HAVE_COMMAND
SETTING_UINT("network_cmd_port", &settings->uints.network_cmd_port, true, network_cmd_port, false);
#endif
Expand Down
1 change: 1 addition & 0 deletions configuration.h
Expand Up @@ -325,6 +325,7 @@ typedef struct settings
unsigned keymapper_port;
unsigned video_window_x;
unsigned video_window_y;
unsigned video_window_opacity;
unsigned video_monitor_index;
unsigned video_fullscreen_x;
unsigned video_fullscreen_y;
Expand Down
10 changes: 10 additions & 0 deletions gfx/common/win32_common.c
Expand Up @@ -45,6 +45,7 @@
#include "../../input/input_driver.h"
#include "../../input/input_keymaps.h"
#include "../video_thread_wrapper.h"
#include "../video_display_server.h"
#include <shellapi.h>

#ifdef HAVE_MENU
Expand Down Expand Up @@ -742,6 +743,7 @@ bool win32_window_create(void *data, unsigned style,
RECT *mon_rect, unsigned width,
unsigned height, bool fullscreen)
{
settings_t *settings = config_get_ptr();
#ifndef _XBOX
main_window.hwnd = CreateWindowEx(0,
"RetroArch", "RetroArch",
Expand All @@ -756,6 +758,14 @@ bool win32_window_create(void *data, unsigned style,
video_driver_display_type_set(RARCH_DISPLAY_WIN32);
video_driver_display_set(0);
video_driver_window_set((uintptr_t)main_window.hwnd);

#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500
/* Windows 2000 and above use layered windows to enable transparency */
SetWindowLongPtr(main_window.hwnd,
GWL_EXSTYLE,
GetWindowLongPtr(main_window.hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
SetLayeredWindowAttributes(main_window.hwnd, 0, (255 * settings->uints.video_window_opacity) / 100, LWA_ALPHA);
#endif
#endif
return true;
}
Expand Down
44 changes: 44 additions & 0 deletions gfx/display_servers/dispserv_null.c
@@ -0,0 +1,44 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2016-2017 - Brad Parker
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/

#include <stddef.h>
#include "../video_display_server.h"

static void* null_display_server_init(void)
{
return NULL;
}

static void null_display_server_destroy(void)
{

}

static bool null_set_window_opacity(void *data, unsigned opacity)
{
(void)data;
(void)opacity;
return true;
}

const video_display_server_t dispserv_null = {
null_display_server_init,
null_display_server_destroy,
null_set_window_opacity,
"null"
};

60 changes: 60 additions & 0 deletions gfx/display_servers/dispserv_win32.c
@@ -0,0 +1,60 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2016-2017 - Brad Parker
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/

#include <windows.h>
#include "../video_display_server.h"
#include "../common/win32_common.h"

typedef struct
{
unsigned opacity;
} dispserv_win32_t;

static void* win32_display_server_init(void)
{
dispserv_win32_t *dispserv = (dispserv_win32_t*)calloc(1, sizeof(*dispserv));

return dispserv;
}

static void win32_display_server_destroy(void)
{

}

static bool win32_set_window_opacity(void *data, unsigned opacity)
{
HWND hwnd = win32_get_window();
dispserv_win32_t *serv = (dispserv_win32_t*)data;

serv->opacity = opacity;

#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500
/* Set window transparency on Windows 2000 and above */
return SetLayeredWindowAttributes(hwnd, 0, opacity, LWA_ALPHA);
#else
return false;
#endif
}

const video_display_server_t dispserv_win32 = {
win32_display_server_init,
win32_display_server_destroy,
win32_set_window_opacity,
"win32"
};

57 changes: 57 additions & 0 deletions gfx/video_display_server.c
@@ -0,0 +1,57 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2016-2017 - Brad Parker
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>
#include "video_display_server.h"
#include "video_driver.h"
#include "../verbosity.h"

static const video_display_server_t *current_display_server = NULL;
static void *current_display_server_data = NULL;

void* video_display_server_init(void)
{
enum rarch_display_type type = video_driver_display_type_get();

switch (type)
{
#if defined(_WIN32) && !defined(_XBOX)
case RARCH_DISPLAY_WIN32:
current_display_server = &dispserv_win32;
break;
#endif
default:
current_display_server = &dispserv_null;
break;
}

current_display_server_data = current_display_server->init();

RARCH_LOG("[Video]: Found display server: %s\n", current_display_server->ident);

return current_display_server_data;
}

void video_display_server_destroy(void)
{

}

bool video_display_server_set_window_opacity(unsigned opacity)
{
return current_display_server->set_window_opacity(current_display_server_data, opacity);
}
43 changes: 43 additions & 0 deletions gfx/video_display_server.h
@@ -0,0 +1,43 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2016-2017 - Brad Parker
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __VIDEO_DISPLAY_SERVER__H
#define __VIDEO_DISPLAY_SERVER__H

#include <retro_common_api.h>
#include <boolean.h>

RETRO_BEGIN_DECLS

typedef struct video_display_server
{
void *(*init)(void);
void (*destroy)(void);
bool (*set_window_opacity)(void *data, unsigned opacity);
const char *ident;
} video_display_server_t;

void* video_display_server_init(void);
void video_display_server_destroy(void);
bool video_display_server_set_window_opacity(unsigned opacity);

extern const video_display_server_t dispserv_win32;
extern const video_display_server_t dispserv_null;

RETRO_END_DECLS

#endif
4 changes: 4 additions & 0 deletions gfx/video_driver.c
Expand Up @@ -48,6 +48,7 @@

#include "video_thread_wrapper.h"
#include "video_driver.h"
#include "video_display_server.h"

#include "../frontend/frontend_driver.h"
#include "../record/record_driver.h"
Expand Down Expand Up @@ -1089,6 +1090,8 @@ static bool video_driver_init_internal(bool *video_is_threaded)

video_context_driver_reset();

video_display_server_init();

return true;

error:
Expand Down Expand Up @@ -1550,6 +1553,7 @@ static void video_driver_lock_new(void)

void video_driver_destroy(void)
{
video_display_server_destroy();
video_driver_cb_has_focus = null_driver_has_focus;
video_driver_use_rgba = false;
video_driver_data_own = false;
Expand Down
5 changes: 3 additions & 2 deletions griffin/griffin.c
Expand Up @@ -188,9 +188,8 @@ VIDEO CONTEXT
#include "../gfx/drivers_context/wgl_ctx.c"
#endif

#if defined(_WIN32) && !defined(_XBOX)
#include "../gfx/drivers_context/gdi_ctx.c"
#endif
#include "../gfx/display_servers/dispserv_win32.c"

#if defined(HAVE_FFMPEG)
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES3)
Expand Down Expand Up @@ -371,6 +370,7 @@ VIDEO DRIVER
#endif

#include "../gfx/drivers_renderchain/null_renderchain.c"
#include "../gfx/display_servers/dispserv_null.c"

#ifdef HAVE_OPENGL
#include "../gfx/common/gl_common.c"
Expand Down Expand Up @@ -746,6 +746,7 @@ AUDIO
DRIVERS
============================================================ */
#include "../gfx/video_driver.c"
#include "../gfx/video_display_server.c"
#include "../gfx/video_coord_array.c"
#include "../input/input_driver.c"
#include "../audio/audio_driver.c"
Expand Down
2 changes: 2 additions & 0 deletions intl/msg_hash_ja.h
Expand Up @@ -3263,3 +3263,5 @@ MSG_HASH(MENU_ENUM_SUBLABEL_AUTOMATICALLY_ADD_CONTENT_TO_PLAYLIST,
"Automatically scans loaded content so they appear inside playlists.")
MSG_HASH(MSG_SCANNING_OF_FILE_FINISHED,
"Scanning of file finished")
MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_WINDOW_OPACITY,
"ウィンドウの不透明性")
2 changes: 2 additions & 0 deletions intl/msg_hash_lbl.h
Expand Up @@ -1377,3 +1377,5 @@ MSG_HASH(MENU_ENUM_LABEL_FRAMECOUNT_SHOW,
"framecount_show")
MSG_HASH(MENU_ENUM_LABEL_AUTOMATICALLY_ADD_CONTENT_TO_PLAYLIST,
"automatically_add_content_to_playlist")
MSG_HASH(MENU_ENUM_LABEL_VIDEO_WINDOW_OPACITY,
"video_window_opacity")
2 changes: 2 additions & 0 deletions intl/msg_hash_us.h
Expand Up @@ -3341,3 +3341,5 @@ MSG_HASH(MENU_ENUM_SUBLABEL_AUTOMATICALLY_ADD_CONTENT_TO_PLAYLIST,
"Automatically scans loaded content so they appear inside playlists.")
MSG_HASH(MSG_SCANNING_OF_FILE_FINISHED,
"Scanning of file finished")
MSG_HASH(MENU_ENUM_LABEL_VALUE_VIDEO_WINDOW_OPACITY,
"Window Opacity")
3 changes: 3 additions & 0 deletions menu/menu_displaylist.c
Expand Up @@ -6028,6 +6028,9 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_VIDEO_WINDOW_HEIGHT,
PARSE_ONLY_UINT, false);
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_VIDEO_WINDOW_OPACITY,
PARSE_ONLY_UINT, false);
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_VIDEO_SCALE_INTEGER,
PARSE_ONLY_BOOL, false);
Expand Down

0 comments on commit 767a1f3

Please sign in to comment.