Merge branch 'linux'

This commit is contained in:
Vinyl Darkscratch 2018-05-03 01:57:49 -07:00
commit 4da276e2bb
7 changed files with 310 additions and 481 deletions

View file

@ -75,6 +75,9 @@ void fileIntBindingInit();
void journalBindingInit(); void journalBindingInit();
void wallpaperBindingInit(); void wallpaperBindingInit();
#ifdef __linux__
void wallpaperBindingTerminate();
#endif
void nikoBindingInit(); void nikoBindingInit();
void oneshotBindingInit(); void oneshotBindingInit();
void steamBindingInit(); void steamBindingInit();
@ -621,6 +624,9 @@ static void mriBindingExecute()
static void mriBindingTerminate() static void mriBindingTerminate()
{ {
rb_raise(rb_eSystemExit, " "); rb_raise(rb_eSystemExit, " ");
#ifdef __linux__
wallpaperBindingTerminate();
#endif
} }
static void mriBindingReset() static void mriBindingReset()

View file

@ -32,7 +32,6 @@ RB_METHOD(oneshotMsgBox)
RB_METHOD(oneshotTextInput) RB_METHOD(oneshotTextInput)
{ {
// const char* prompt, int char_limit, const char* font
RB_UNUSED_PARAM; RB_UNUSED_PARAM;
VALUE prompt; VALUE prompt;
int char_limit = 100; int char_limit = 100;
@ -79,12 +78,14 @@ RB_METHOD(oneshotShake)
RB_UNUSED_PARAM; RB_UNUSED_PARAM;
int absx, absy; int absx, absy;
SDL_GetWindowPosition(shState->rtData().window, &absx, &absy); SDL_GetWindowPosition(shState->rtData().window, &absx, &absy);
int state;
srand(time(NULL)); srand(time(NULL));
for (int i = 0; i < 60; ++i) { for (int i = 0; i < 60; ++i) {
int max = 60 - i; int max = 60 - i;
int x = rand() % (max * 2) - max; int x = rand() % (max * 2) - max;
int y = rand() % (max * 2) - max; int y = rand() % (max * 2) - max;
SDL_SetWindowPosition(shState->rtData().window, absx + x, absy + y); SDL_SetWindowPosition(shState->rtData().window, absx + x, absy + y);
rb_eval_string_protect("sleep 0.02", &state);
} }
return Qnil; return Qnil;
} }

View file

@ -5,8 +5,7 @@
#include "binding-util.h" #include "binding-util.h"
#include "binding-types.h" #include "binding-types.h"
#include "config.h" #include "config.h"
#include "oneshot.h"
static bool isCached = false;
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
@ -18,42 +17,95 @@ static bool isCached = false;
static DWORD szTileSize = sizeof(szTile) - 1; static DWORD szTileSize = sizeof(szTile) - 1;
static bool setStyle = false; static bool setStyle = false;
static bool setTile = false; static bool setTile = false;
static bool isCached = false;
#else #else
#ifdef __APPLE__ #ifdef __APPLE__
#include "mac-desktop.h" #include "mac-desktop.h"
static bool isCached = false;
#else #else
#include <giomm/settings.h> #include <giomm/settings.h>
#include <xfconf/xfconf.h>
#include <unistd.h> #include <unistd.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <sstream> #include <sstream>
Glib::RefPtr<Gio::Settings> bgsetting = Gio::Settings::create("org.gnome.desktop.background"); static std::string desktop = "uninitialized";
std::string defPictureURI = bgsetting->get_string("picture-uri"); // GNOME settings
std::string defPictureOptions = bgsetting->get_string("picture-options"); static Glib::RefPtr<Gio::Settings> bgsetting;
std::string defPrimaryColor = bgsetting->get_string("primary-color"); static std::string defPictureURI, defPictureOptions, defPrimaryColor, defColorShading;
// XFCE settings
static XfconfChannel* bgchannel;
static int defPictureStyle;
static int defColorStyle;
static GValue defColor = G_VALUE_INIT;
static bool defColorExists;
static std::string optionImage, optionColor, optionImageStyle, optionColorStyle;
#endif #endif
#endif #endif
#ifdef __linux__
void desktopEnvironmentInit()
{
if (desktop != "uninitialized") {
return;
}
desktop = shState->oneshot().desktopEnv;
if (desktop == "gnome" || desktop == "mate") {
if (desktop == "gnome") {
bgsetting = Gio::Settings::create("org.gnome.desktop.background");
defPictureURI = bgsetting->get_string("picture-uri");
} else {
bgsetting = Gio::Settings::create("org.mate.background");
defPictureURI = bgsetting->get_string("picture-filename");
}
defPictureOptions = bgsetting->get_string("picture-options");
defPrimaryColor = bgsetting->get_string("primary-color");
defColorShading = bgsetting->get_string("color-shading-type");
} else if (desktop == "xfce") {
GError *xferror = NULL;
if (xfconf_init(&xferror)) {
bgchannel = xfconf_channel_get("xfce4-desktop");
std::string optionPrefix = "/backdrop/screen0/monitor0/workspace0/";
optionImage = optionPrefix + "last-image";
optionColor = optionPrefix + "color1";
optionImageStyle = optionPrefix + "image-style";
optionColorStyle = optionPrefix + "color-style";
defPictureURI = xfconf_channel_get_string(bgchannel, optionImage.c_str(), "");
defPictureStyle = xfconf_channel_get_int(bgchannel, optionImageStyle.c_str(), -1);
defColorExists = xfconf_channel_get_property(bgchannel, optionColor.c_str(), &defColor);
defColorStyle = xfconf_channel_get_int(bgchannel, optionColorStyle.c_str(), -1);
} else {
// Configuration failed to initialize, we won't set the wallpaper
desktop = "xfce_error";
g_error_free(xferror);
}
}
}
#endif
RB_METHOD(wallpaperSet) RB_METHOD(wallpaperSet)
{ {
RB_UNUSED_PARAM; RB_UNUSED_PARAM;
const char *iname; const char *name;
int color; int color;
rb_get_args(argc, argv, "zi", &iname, &color RB_ARG_END); rb_get_args(argc, argv, "zi", &name, &color RB_ARG_END);
std::string imageName = iname; std::string path;
std::string imgname = shState->config().gameFolder + "/Wallpaper/" + imageName + ".bmp";
#ifdef _WIN32 #ifdef _WIN32
std::cout << "Setting wallpaper to " << imgname << std::endl; path = shState->config().gameFolder + "\\Wallpaper\\" + name + ".bmp";
std::cout << "Setting wallpaper to " << path << std::endl;
// Crapify the slashes // Crapify the slashes
size_t index = 0; size_t index = 0;
for (;;) { for (;;) {
index = imgname.find("/", index); index = path.find("/", index);
if (index == std::string::npos) if (index == std::string::npos)
break; break;
imgname.replace(index, 1, "\\"); path.replace(index, 1, "\\");
index += 1; index += 1;
} }
WCHAR imgnameW[MAX_PATH]; WCHAR imgnameW[MAX_PATH];
WCHAR imgnameFull[MAX_PATH]; WCHAR imgnameFull[MAX_PATH];
MultiByteToWideChar(CP_UTF8, 0, imgname.c_str(), -1, imgnameW, MAX_PATH); MultiByteToWideChar(CP_UTF8, 0, path.c_str(), -1, imgnameW, MAX_PATH);
GetFullPathNameW(imgnameW, MAX_PATH, imgnameFull, NULL); GetFullPathNameW(imgnameW, MAX_PATH, imgnameFull, NULL);
@ -109,29 +161,87 @@ end:
if (hKey) if (hKey)
RegCloseKey(hKey); RegCloseKey(hKey);
#else #else
std::size_t found = imageName.find("w32"); std::string nameFix(name);
if (found != std::string::npos) imageName.replace(imageName.end()-3, imageName.end(), "unix"); std::size_t found = nameFix.find("w32");
imgname = shState->config().gameFolder + "/Wallpaper/" + imageName + ".png"; if (found != std::string::npos) {
nameFix.replace(nameFix.end()-3, nameFix.end(), "unix");
}
path = "/Wallpaper/" + nameFix + ".png";
std::cout << "Setting wallpaper to " << imgname << std::endl; std::cout << "Setting wallpaper to " << path << std::endl;
#ifdef __APPLE__ #ifdef __APPLE__
if (!isCached) { if (!isCached) {
MacDesktop::CacheCurrentBackground(); MacDesktop::CacheCurrentBackground();
isCached = true; isCached = true;
} }
MacDesktop::ChangeBackground(imgname, ((color >> 16) & 0xFF) / 255.0, ((color >> 8) & 0xFF) / 255.0, ((color) & 0xFF) / 255.0); MacDesktop::ChangeBackground(shState->config().gameFolder + path, ((color >> 16) & 0xFF) / 255.0, ((color >> 8) & 0xFF) / 255.0, (color & 0xFF) / 255.0);
#else #else
char gameDir[1024]; char gameDir[PATH_MAX];
if (getcwd(gameDir, sizeof(gameDir)) != NULL) { if (getcwd(gameDir, sizeof(gameDir)) == NULL) {
return Qnil;
}
std::string gameDirStr(gameDir); std::string gameDirStr(gameDir);
desktopEnvironmentInit();
if (desktop == "gnome" || desktop == "mate") {
std::stringstream hexColor; std::stringstream hexColor;
hexColor << "#" << std::hex << color; hexColor << "#" << std::hex << color;
bgsetting->set_string("picture-uri", "file://" + gameDirStr + "/Wallpaper/" + imageName + ".png"); if (desktop == "gnome") {
bgsetting->set_string("picture-uri", "file://" + gameDirStr + path);
} else {
bgsetting->set_string("picture-filename", gameDirStr + path);
}
bgsetting->set_string("picture-options", "scaled"); bgsetting->set_string("picture-options", "scaled");
bgsetting->set_string("primary-color", hexColor.str()); bgsetting->set_string("primary-color", hexColor.str());
} else { bgsetting->set_string("color-shading-type", "solid");
// Error handling? } else if (desktop == "xfce") {
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = color & 0xFF;
unsigned int ur = r * 256 + r;
unsigned int ug = g * 256 + g;
unsigned int ub = b * 256 + b;
unsigned int alpha = 65535;
std::string concatPath(gameDirStr + path);
xfconf_channel_set_string(bgchannel, optionImage.c_str(), concatPath.c_str());
xfconf_channel_set_int(bgchannel, optionColorStyle.c_str(), 0);
xfconf_channel_set_int(bgchannel, optionImageStyle.c_str(), 4);
GValue colorValue = G_VALUE_INIT;
GPtrArray *colorArr = g_ptr_array_sized_new(4);
GType colorArrType = g_type_from_name("GPtrArray_GValue_");
if (!colorArrType) {
std::stringstream colorCommand;
colorCommand << "xfconf-query -c xfce4-desktop -n -p " << optionColor
<< " -t uint -t uint -t uint -t uint -s " << ub
<< " -s " << ug << " -s " << ub << " -s " << alpha;
int colorCommandRes = system(colorCommand.str().c_str());
defColorExists = xfconf_channel_get_property(bgchannel, optionColor.c_str(), &defColor);
colorArrType = g_type_from_name("GPtrArray_GValue_");
if (!colorArrType) {
// Let's do some debug output here and skip changing the color
std::cout << "WALLPAPER ERROR: xfconf-query call returned" << colorCommandRes;
return Qnil;
}
}
g_value_init(&colorValue, colorArrType);
GValue *vr = g_new0(GValue, 1);
GValue *vg = g_new0(GValue, 1);
GValue *vb = g_new0(GValue, 1);
GValue *va = g_new0(GValue, 1);
g_value_init(vr, G_TYPE_UINT);
g_value_init(vg, G_TYPE_UINT);
g_value_init(vb, G_TYPE_UINT);
g_value_init(va, G_TYPE_UINT);
g_value_set_uint(vr, ur);
g_value_set_uint(vg, ug);
g_value_set_uint(vb, ub);
g_value_set_uint(va, alpha);
g_ptr_array_add(colorArr, vr);
g_ptr_array_add(colorArr, vg);
g_ptr_array_add(colorArr, vb);
g_ptr_array_add(colorArr, va);
g_value_set_boxed(&colorValue, colorArr);
xfconf_channel_set_property(bgchannel, optionColor.c_str(), &colorValue);
} }
#endif #endif
#endif #endif
@ -170,9 +280,38 @@ RB_METHOD(wallpaperReset)
#ifdef __APPLE__ #ifdef __APPLE__
MacDesktop::ResetBackground(); MacDesktop::ResetBackground();
#else #else
desktopEnvironmentInit();
if (desktop == "gnome" || desktop == "mate") {
if (desktop == "gnome") {
bgsetting->set_string("picture-uri", defPictureURI); bgsetting->set_string("picture-uri", defPictureURI);
} else {
bgsetting->set_string("picture-filename", defPictureURI);
}
bgsetting->set_string("picture-options", defPictureOptions); bgsetting->set_string("picture-options", defPictureOptions);
bgsetting->set_string("primary-color", defPrimaryColor); bgsetting->set_string("primary-color", defPrimaryColor);
bgsetting->set_string("color-shading-type", defColorShading);
} else if (desktop == "xfce") {
if (defColorExists) {
xfconf_channel_set_property(bgchannel, optionColor.c_str(), &defColor);
} else {
xfconf_channel_reset_property(bgchannel, optionColor.c_str(), false);
}
if (defPictureURI == "") {
xfconf_channel_reset_property(bgchannel, optionImage.c_str(), false);
} else {
xfconf_channel_set_string(bgchannel, optionImage.c_str(), defPictureURI.c_str());
}
if (defPictureStyle == -1) {
xfconf_channel_reset_property(bgchannel, optionImageStyle.c_str(), false);
} else {
xfconf_channel_set_int(bgchannel, optionImageStyle.c_str(), defPictureStyle);
}
if (defColorStyle == -1) {
xfconf_channel_reset_property(bgchannel, optionColorStyle.c_str(), false);
} else {
xfconf_channel_set_int(bgchannel, optionColorStyle.c_str(), defColorStyle);
}
}
#endif #endif
#endif #endif
return Qnil; return Qnil;
@ -186,3 +325,14 @@ void wallpaperBindingInit()
_rb_define_module_function(module, "set", wallpaperSet); _rb_define_module_function(module, "set", wallpaperSet);
_rb_define_module_function(module, "reset", wallpaperReset); _rb_define_module_function(module, "reset", wallpaperReset);
} }
#ifdef __linux__
void wallpaperBindingTerminate()
{
// Clean up
// We assume Gio::Settings destructor will be automatically called
if (desktop == "xfce") {
xfconf_shutdown();
}
}
#endif

View file

@ -47,9 +47,9 @@ unix {
SOURCES += src/mac-desktop.mm SOURCES += src/mac-desktop.mm
} }
!macx: { !macx: {
PKGCONFIG += giomm-2.4 QMAKE_CXXFLAGS += -g
PKGCONFIG += giomm-2.4 gtk+-3.0 gdk-3.0 libxfconf-0
INCLUDEPATH += /usr/include/AL /usr/local/include/AL INCLUDEPATH += /usr/include/AL /usr/local/include/AL
SOURCES += src/xdg-user-dir-lookup.c
LIBS += -lX11 LIBS += -lX11
} }
} }

View file

@ -277,7 +277,7 @@ void EventThread::process(RGSSThreadData &rtData)
#ifdef __APPLE__ #ifdef __APPLE__
case SDL_WINDOWEVENT_MOVED: case SDL_WINDOWEVENT_MOVED:
if (event.window.data1 && event.window.data2) if (shState != NULL && event.window.data1 && event.window.data2)
shState->oneshot().setWindowPos(event.window.data1, event.window.data2); shState->oneshot().setWindowPos(event.window.data1, event.window.data2);
break; break;
#endif #endif
@ -590,7 +590,7 @@ int EventThread::eventFilter(void *data, SDL_Event *event)
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
if (event->window.event == SDL_WINDOWEVENT_MOVED) if (event->window.event == SDL_WINDOWEVENT_MOVED)
{ {
if (shState->rgssVersion > 0) if (shState != NULL && shState->rgssVersion > 0)
{ {
shState->oneshot().setWindowPos(event->window.data1, event->window.data2); shState->oneshot().setWindowPos(event->window.data1, event->window.data2);
shState->graphics().update(false); shState->graphics().update(false);

View file

@ -33,41 +33,8 @@
#define OS_OSX #define OS_OSX
#else #else
#define OS_LINUX #define OS_LINUX
#include <gtk/gtk.h>
class GtkWidget; #include <gdk/gdk.h>
typedef enum
{
GTK_MESSAGE_INFO,
GTK_MESSAGE_WARNING,
GTK_MESSAGE_QUESTION,
GTK_MESSAGE_ERROR
} GtkMessageType;
typedef enum
{
GTK_BUTTONS_NONE,
GTK_BUTTONS_OK,
GTK_BUTTONS_CLOSE,
GTK_BUTTONS_CANCEL,
GTK_BUTTONS_YES_NO,
GTK_BUTTONS_OK_CANCEL
} GtkButtonsType;
typedef enum
{
GTK_RESPONSE_NONE = -1,
GTK_RESPONSE_REJECT = -2,
GTK_RESPONSE_ACCEPT = -3,
GTK_RESPONSE_DELETE_EVENT = -4,
GTK_RESPONSE_OK = -5,
GTK_RESPONSE_CANCEL = -6,
GTK_RESPONSE_CLOSE = -7,
GTK_RESPONSE_YES = -8,
GTK_RESPONSE_NO = -9,
GTK_RESPONSE_APPLY = -10,
GTK_RESPONSE_HELP = -11
} GtkResponseType;
#endif #endif
#else #else
#error "Operating system not detected." #error "Operating system not detected."
@ -103,35 +70,15 @@ struct OneshotPrivate
std::vector<uint8_t> obscuredMap; std::vector<uint8_t> obscuredMap;
bool obscuredCleared; bool obscuredCleared;
#if defined OS_LINUX
//GTK+
void *libgtk;
void (*gtk_init)(int *argc, char ***argv);
GtkWidget *(*gtk_message_dialog_new)(void *parent, int flags, GtkMessageType type, GtkButtonsType buttons, const char *message_format, ...);
void (*gtk_window_set_title)(GtkWidget *window, const char *title);
GtkResponseType (*gtk_dialog_run)(GtkWidget *dialog);
void (*gtk_widget_destroy)(GtkWidget *widget);
void (*gtk_main_quit)();
void (*gtk_main)();
unsigned int (*gdk_threads_add_idle)(int (*function)(void *data), void *data);
#endif
OneshotPrivate() OneshotPrivate()
: window(0), : window(0),
winMutex(SDL_CreateMutex()) winMutex(SDL_CreateMutex())
#if defined OS_LINUX
,libgtk(0)
#endif
{ {
} }
~OneshotPrivate() ~OneshotPrivate()
{ {
SDL_DestroyMutex(winMutex); SDL_DestroyMutex(winMutex);
#ifdef OS_LINUX
if (libgtk)
dlclose(libgtk);
#endif
} }
}; };
@ -140,7 +87,6 @@ struct OneshotPrivate
struct linux_DialogData struct linux_DialogData
{ {
// Input // Input
OneshotPrivate *p;
int type; int type;
const char *body; const char *body;
const char *title; const char *title;
@ -152,7 +98,6 @@ struct linux_DialogData
static int linux_dialog(void *rawData) static int linux_dialog(void *rawData)
{ {
linux_DialogData *data = reinterpret_cast<linux_DialogData*>(rawData); linux_DialogData *data = reinterpret_cast<linux_DialogData*>(rawData);
OneshotPrivate *p = data->p;
// Determine correct flags // Determine correct flags
GtkMessageType gtktype; GtkMessageType gtktype;
@ -173,19 +118,19 @@ static int linux_dialog(void *rawData)
gtktype = GTK_MESSAGE_ERROR; gtktype = GTK_MESSAGE_ERROR;
break; break;
default: default:
p->gtk_main_quit(); gtk_main_quit();
return 0; return 0;
} }
// Display dialog and get result // Display dialog and get result
GtkWidget *dialog = p->gtk_message_dialog_new(0, 0, gtktype, gtkbuttons, data->body); GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, gtktype, gtkbuttons, data->body);
p->gtk_window_set_title(dialog, data->title); gtk_window_set_title(GTK_WINDOW(dialog), data->title);
int result = p->gtk_dialog_run(dialog); int result = gtk_dialog_run(GTK_DIALOG(dialog));
p->gtk_widget_destroy(dialog); gtk_widget_destroy(dialog);
// Interpret result and return // Interpret result and return
data->result = (result == GTK_RESPONSE_OK || result == GTK_RESPONSE_YES); data->result = (result == GTK_RESPONSE_OK || result == GTK_RESPONSE_YES);
p->gtk_main_quit(); gtk_main_quit();
return 0; return 0;
} }
#elif defined OS_W32 #elif defined OS_W32
@ -225,130 +170,6 @@ static WCHAR *w32_toWide(const char *str)
} }
#endif #endif
LTexture::LTexture() {
//Initialize
mTexture = NULL;
mWidth = 0;
mHeight = 0;
}
LTexture::~LTexture() {
//Deallocate
free();
}
bool LTexture::loadFromFile(std::string path, SDL_Renderer *gRenderer) {
//Get rid of preexisting texture
free();
//The final texture
SDL_Texture *newTexture = NULL;
//Load image at specified path
SDL_Surface *loadedSurface = IMG_Load(path.c_str());
if (loadedSurface == NULL) {
printf("Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError());
} else {
//Color key image
SDL_SetColorKey(loadedSurface, SDL_TRUE, SDL_MapRGB(loadedSurface->format, 0, 0xFF, 0xFF));
//Create texture from surface pixels
newTexture = SDL_CreateTextureFromSurface(gRenderer, loadedSurface);
if (newTexture == NULL) {
printf("Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError());
} else {
//Get image dimensions
mWidth = loadedSurface->w;
mHeight = loadedSurface->h;
}
//Get rid of old loaded surface
SDL_FreeSurface(loadedSurface);
}
//Return success
mTexture = newTexture;
return mTexture != NULL;
}
#ifdef _SDL_TTF_H
bool LTexture::loadFromRenderedText(std::string textureText, SDL_Color textColor, SDL_Renderer *gRenderer, TTF_Font *gFont) {
//Get rid of preexisting texture
free();
//Render text surface
SDL_Surface *textSurface = TTF_RenderText_Solid(gFont, textureText.c_str(), textColor);
if (textSurface != NULL) {
//Create texture from surface pixels
mTexture = SDL_CreateTextureFromSurface(gRenderer, textSurface);
if (mTexture == NULL) {
printf("Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError());
} else {
//Get image dimensions
mWidth = textSurface->w;
mHeight = textSurface->h;
}
//Get rid of old surface
SDL_FreeSurface(textSurface);
} else {
printf("Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError());
}
//Return success
return mTexture != NULL;
}
#endif
void LTexture::free() {
//Free texture if it exists
if (mTexture != NULL) {
SDL_DestroyTexture(mTexture);
mTexture = NULL;
mWidth = 0;
mHeight = 0;
}
}
void LTexture::setColor(Uint8 red, Uint8 green, Uint8 blue) {
//Modulate texture rgb
SDL_SetTextureColorMod(mTexture, red, green, blue);
}
void LTexture::setBlendMode(SDL_BlendMode blending) {
//Set blending function
SDL_SetTextureBlendMode(mTexture, blending);
}
void LTexture::setAlpha(Uint8 alpha) {
//Modulate texture alpha
SDL_SetTextureAlphaMod(mTexture, alpha);
}
void LTexture::render(SDL_Renderer *gRenderer, int x, int y, SDL_Rect *clip, double angle, SDL_Point *center,
SDL_RendererFlip flip) {
//Set rendering space and render to screen
SDL_Rect renderQuad = {x, y, mWidth, mHeight };
//Set clip rendering dimensions
if (clip != NULL) {
renderQuad.w = clip->w;
renderQuad.h = clip->h;
}
//Render to screen
SDL_RenderCopyEx(gRenderer, mTexture, clip, &renderQuad, angle, center, flip);
}
int LTexture::getWidth() {
return mWidth;
}
int LTexture::getHeight() {
return mHeight;
}
Oneshot::Oneshot(RGSSThreadData &threadData) : Oneshot::Oneshot(RGSSThreadData &threadData) :
threadData(threadData) threadData(threadData)
{ {
@ -450,56 +271,24 @@ Oneshot::Oneshot(RGSSThreadData &threadData) :
#endif #endif
#endif #endif
/********** #ifdef __linux__
* MSGBOX std::string desktop(getenv("XDG_CURRENT_DESKTOP"));
**********/ std::transform(desktop.begin(), desktop.end(), desktop.begin(), ::tolower);
#ifdef OS_LINUX if (
#define LOAD_FUNC(name) *reinterpret_cast<void**>(&p->name) = dlsym(p->libgtk, #name) desktop.find("cinnamon") != std::string::npos ||
//Attempt to link to gtk (prefer gtk2 over gtk3 until I can figure that message box icon out) desktop.find("gnome") != std::string::npos ||
static const char *gtklibs[] = desktop.find("unity") != std::string::npos
{ ) {
"libgtk-x11-2.0.so", desktopEnv = "gnome";
"libgtk-3.0.so", gtk_init(0, 0);
}; } else if (desktop.find("mate") != std::string::npos) {
desktopEnv = "mate";
for (size_t i = 0; i < ARRAY_SIZE(gtklibs); ++i) gtk_init(0, 0);
{ } else if (desktop.find("xfce") != std::string::npos) {
if (!(p->libgtk = dlopen("libgtk-x11-2.0.so", RTLD_NOW))) desktopEnv = "xfce";
p->libgtk = dlopen("libgtk-3.0.so", RTLD_NOW);
if (p->libgtk)
{
//Load functions
LOAD_FUNC(gtk_init);
LOAD_FUNC(gtk_message_dialog_new);
LOAD_FUNC(gtk_window_set_title);
LOAD_FUNC(gtk_dialog_run);
LOAD_FUNC(gtk_widget_destroy);
LOAD_FUNC(gtk_main_quit);
LOAD_FUNC(gtk_main);
LOAD_FUNC(gdk_threads_add_idle);
if (p->gtk_init
&& p->gtk_message_dialog_new
&& p->gtk_window_set_title
&& p->gtk_dialog_run
&& p->gtk_widget_destroy
&& p->gtk_main_quit
&& p->gtk_main
&& p->gdk_threads_add_idle)
{
p->gtk_init(0, 0);
} }
else
{
dlclose(p->libgtk);
p->libgtk = 0;
}
}
if (p->libgtk)
break;
}
#undef LOAD_FUNC
#endif #endif
/******** /********
* MISC * MISC
********/ ********/
@ -668,49 +457,11 @@ bool Oneshot::msgbox(int type, const char *body, const char *title)
{ {
if (!title) if (!title)
title = ""; title = "";
#if 0
//Get native window handle
SDL_SysWMinfo wminfo;
SDL_version version;
SDL_VERSION(&version);
wminfo.version = version;
SDL_GetWindowWMInfo(p->window, &wminfo);
HWND hwnd = wminfo.info.win.window;
//Construct flags
UINT flags = 0;
switch (type)
{
case MSG_INFO:
flags = MB_ICONINFORMATION;
break;
case MSG_YESNO:
flags = MB_ICONQUESTION | MB_YESNO;
break;
case MSG_WARN:
flags = MB_ICONWARNING;
break;
case MSG_ERR:
flags = MB_ICONERROR;
break;
}
//Create message box
WCHAR *wbody = w32_toWide(body);
WCHAR *wtitle = w32_toWide(title);
int result = MessageBoxW(N, wbody, wtitle, flags);
delete [] title;
delete [] body;
//Interpret result
return (result == IDOK || result == IDYES);
#else
#if defined OS_LINUX #if defined OS_LINUX
if (p->libgtk) if (desktopEnv == "gnome" || desktopEnv == "mate") {
{ linux_DialogData data = {type, body, title, 0};
linux_DialogData data = {p, type, body, title, 0}; gdk_threads_add_idle(linux_dialog, &data);
p->gdk_threads_add_idle(linux_dialog, &data); gtk_main();
p->gtk_main();
return data.result; return data.result;
} }
#endif #endif
@ -782,31 +533,9 @@ bool Oneshot::msgbox(int type, const char *body, const char *title)
int button; int button;
SDL_ShowMessageBox(&data, &button); SDL_ShowMessageBox(&data, &button);
return button ? true : false; return button ? true : false;
#endif
} }
std::string Oneshot::textinput(const char* prompt, int char_limit, const char* fontName) { std::string Oneshot::textinput(const char* prompt, int char_limit, const char* fontName) {
// SDL_Color textColor = {0xFF, 0xFF, 0xFF, 0xFF}; //Set text color as black
// SDL_Renderer *gRenderer = SDL_CreateRenderer(threadData.window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
// // SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
// LTexture gPromptTextTexture;
// LTexture gInputTextTexture;
// //Open the font
// TTF_Font *gFont = TTF_OpenFont("VL-Gothic-Regular.ttf", 18); // XXX Implement font changing
// if (gFont == NULL) {
// printf("Failed to load lazy font! SDL_ttf Error: %s\n", TTF_GetError());
// // success = false;
// } else {
// //Render the prompt
// if (!gPromptTextTexture.loadFromRenderedText(prompt, textColor, gRenderer, gFont)) {
// printf("Failed to render prompt text!\n");
// // success = false;
// }
// }
// gInputTextTexture.loadFromRenderedText(threadData.inputText.c_str(), textColor, gRenderer, gFont);
std::vector<std::string> *fontNames = new std::vector<std::string>(); std::vector<std::string> *fontNames = new std::vector<std::string>();
fontNames->push_back(fontName); fontNames->push_back(fontName);
fontNames->push_back("VL Gothic"); fontNames->push_back("VL Gothic");
@ -832,22 +561,7 @@ std::string Oneshot::textinput(const char* prompt, int char_limit, const char* f
inputBmp->clear(); inputBmp->clear();
inputBmp->drawText(DEF_SCREEN_W / 2, DEF_SCREEN_H / 2, DEF_SCREEN_W, DEF_SCREEN_H, threadData.inputText.c_str(), 1); inputBmp->drawText(DEF_SCREEN_W / 2, DEF_SCREEN_H / 2, DEF_SCREEN_W, DEF_SCREEN_H, threadData.inputText.c_str(), 1);
inputTextPrev = threadData.inputText; inputTextPrev = threadData.inputText;
// if (threadData.inputText.length() > 0) gInputTextTexture.loadFromRenderedText(threadData.inputText.c_str(), textColor, gRenderer, gFont);
// else gInputTextTexture.loadFromRenderedText(" ", textColor, gRenderer, gFont);
} }
// //Clear screen
// // SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
// SDL_RenderClear(gRenderer);
// //Render text textures
// gPromptTextTexture.render(gRenderer, (DEF_SCREEN_W - gPromptTextTexture.getWidth()) / 2,
// (DEF_SCREEN_H / 2) - gPromptTextTexture.getHeight());
// gInputTextTexture.render(gRenderer, (DEF_SCREEN_W - gInputTextTexture.getWidth()) / 2,
// (DEF_SCREEN_H / 2));
// //Update screen
// SDL_RenderPresent(gRenderer);
} }
// Disable text input // Disable text input

View file

@ -11,52 +11,6 @@
struct OneshotPrivate; struct OneshotPrivate;
struct RGSSThreadData; struct RGSSThreadData;
//Texture wrapper class
class LTexture {
public:
//Initializes variables
LTexture();
//Deallocates memory
~LTexture();
//Loads image at specified path
bool loadFromFile(std::string path, SDL_Renderer *gRenderer);
#ifdef _SDL_TTF_H
//Creates image from font string
bool loadFromRenderedText(std::string textureText, SDL_Color textColor, SDL_Renderer *gRenderer, TTF_Font *gFont);
#endif
//Deallocates texture
void free();
//Set color modulation
void setColor(Uint8 red, Uint8 green, Uint8 blue);
//Set blending
void setBlendMode(SDL_BlendMode blending);
//Set alpha modulation
void setAlpha(Uint8 alpha);
//Renders texture at given point
void render(SDL_Renderer *gRenderer, int x, int y, SDL_Rect *clip = NULL, double angle = 0.0, SDL_Point *center = NULL,
SDL_RendererFlip flip = SDL_FLIP_NONE);
//Gets image dimensions
int getWidth();
int getHeight();
private:
//The actual hardware texture
SDL_Texture *mTexture;
//Image dimensions
int mWidth;
int mHeight;
};
class Oneshot class Oneshot
{ {
public: public:
@ -120,6 +74,10 @@ public:
//Dirty flag for obscured texture //Dirty flag for obscured texture
bool obscuredDirty; bool obscuredDirty;
#ifdef __linux__
std::string desktopEnv;
#endif
private: private:
OneshotPrivate *p; OneshotPrivate *p;
RGSSThreadData &threadData; RGSSThreadData &threadData;